开发者

Jump browser window down to a DOM Element

开发者 https://www.devze.com 2023-01-15 16:52 出处:网络
OK, I\'m sure I\'m justing having a brain-fart after 2 weeks Honeymoon in Tuscany... by brains clear, and I\'m googled out looking for keyw开发者_如何学Pythonords and how to do it, even scanned down t

OK, I'm sure I'm justing having a brain-fart after 2 weeks Honeymoon in Tuscany... by brains clear, and I'm googled out looking for keyw开发者_如何学Pythonords and how to do it, even scanned down the JQuery Valdate.js looking for the bit that does it...

What I want to do is this; but don't know where to start.

if ($("#errorMessage").exists()){

// Jump browser window down to #errorMessage.

}


You can animate it down, like this:

if ($("#errorMessage").length){
  $("html, body").animate({ scrollTop: $("#errorMessage").position().top });
}

You can give it a try here, this just gives a nice transition to the element's positon.


scrollIntoView would probably solve your problems.

And .exists() would be .length > 0


check scrollTop property. you will have to scroll to the position of the element

0

精彩评论

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