当窗口滚动到特定位置时触发事件 [英] Trigger events when the window is scrolled to certain positions

查看:18
本文介绍了当窗口滚动到特定位置时触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在浏览器窗口超出某个点时调用函数
(例如,用户将窗口从顶部向下滚动超过 200 像素

I would like to call functions when the browser window goes beyond a certain point
(e.g the user scrolled the window down beyond 200px from the top

是否有我可以绑定的事件,然后我将如何检查从浏览器顶部到页面顶部的偏移量是多少?

Is there an event I can bind to and then how would I check how much the offset is from the top of the browser to the top of the page?

推荐答案

您可以使用 onscroll

function testScroll(ev){
    if(window.pageYOffset>400)alert('User has scrolled at least 400 px!');
}
window.onscroll=testScroll

如果你想要一个 jQuery 解决方案,你可以使用 scroll.

If you want a jQuery solution you can use scroll.

这篇关于当窗口滚动到特定位置时触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆