开发者

how to scroll window onload with jquery

I have a form in the middle of a table. I would like this form to always be in the center of the window vertical and horizontally, even when the window size is smaller than the table. I am thinking on using the scrollTo function of jQuery and call it onLoad and onResize, http://demos.flesler.com/jquery/scrollTo/ but I am a begginer and I d开发者_开发技巧on't know how to do it. I would appreciate any help or example with the calls in the header and the script function. Thank you very much.


If you want a floater box:
put your form in a DIV , make it's position absolute, center it:
Add this JQuery plugin:
http://plugins.jquery.com/project/elementcenter

$(document).ready(function() {
     $('#div_id').css('position','absolute');
     $('#div_id').center();
});

$(window).resize(function() {
     $('#div_id').center();
});

if you want to scroll:

$(document).ready(function() {
     window.scrollTo(0,$("#FORM_ID").offset().top);
});
$(window).resize(function() {
     window.scrollTo(0,$("#FORM_ID").offset().top);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜