开发者

how to scroll window onload with jquery

开发者 https://www.devze.com 2023-01-10 13:47 出处:网络
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 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

精彩评论

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

关注公众号