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/
精彩评论