开发者

How to scroll a DIV to the top of the browser window based on a condition?

I have a web page that has many divs, containing a number of form fields that the user needs to fill out.

Now within one of the divs, I have a radiogroup option that determines additional DIVs being made available to the 开发者_StackOverflow中文版user for input using jQuery .show().

My question is, when the user selects the radiogroup option, the new DIV appears below this radiogroup option but what I would like, would be a means to scroll this new DIV to the top of the browser so that the user doesn’t miss it below.


Assuming it's the <body> that get scrolled, you could do this:

var newdiv = $('#div_id');

$('body').animate({scrollTop: newdiv.position().top});

Example: http://jsfiddle.net/V36WL/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜