[英]Scroll page on page load if at top of page
I would like to do something if the page is detected to be at the very top of the page otherwise don't do it. 如果检测到页面位于页面的顶部,我想做一些事情,否则不要这样做。 I'm guessing I need to use and if statement somehow but I'm just not sure how to do this.
我猜我需要以某种方式使用if语句,但是我不确定该怎么做。
For example, I want the page to scroll to 125 pixels if the page is at the very top otherwise don't scroll to that position. 例如,如果页面在最顶部,我希望页面滚动到125像素,否则不要滚动到该位置。
$('html, body').animate({scrollTop:125}, 4000); $('html,body')。animate({scrollTop:125},4000);
Use this on load: 加载时使用:
function checkTop(){
if ($(window).scrollTop() == 0) {
$(window).animate({scrollTop:125}, 4000);
}
}
checkTop();
$(window).scroll(function(){
checkTop();
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.