[英]need an event triggered if the page has scrolled 200px down (jQuery)
I want to show and hide a piece of code if i scroll and the page is for example half way, i have tried to use window scroll but this doesnt works(no errors, clean code, different browsers, different jQuery versions), but this doesn't trigger anything, so i am looking for a better way to show and hide a div if i scrolldown. 我想显示和隐藏一段代码,如果我滚动,页面是例如中途,我试图使用窗口滚动,但这不起作用(没有错误,干净的代码,不同的浏览器,不同的jQuery版本),但这不触发任何东西,所以我正在寻找一种更好的方式来显示和隐藏div如果我滚动。
used this to trigger an event(not working) 用它来触发事件(不工作)
$(window).scroll(function(){
alert('works')
});
Try using the window.onload function (that's how they use it in jQuery examples): 尝试使用window.onload函数(这就是他们在jQuery示例中使用它的方式):
window.onload = (function(){
$(window).scroll(function () {
if( $(window).scrollTop() > 200 ) {
// Display something
}
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.