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

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

问题描述

我想调用函数时,浏览器窗口超过一定点结果
(例如,用户从顶部滚动窗口中向下超出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的解决方案。

If you want a jQuery solution you can use scroll.

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

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