gpt4 book ai didi

javascript - 如何获取页面滚动位置(y轴)

转载 作者:行者123 更新时间:2023-11-28 13:35:48 24 4
gpt4 key购买 nike

如何获取浏览器的当前滚动位置?,我想根据页面位置触发事件。这是我尝试过的:

var scroll_position=document.viewport.getScrollOffsets();

window.onscroll = function (event) {

if(scroll_position>1000)
{
alert('xxxxxxxxxxx');
}

最佳答案

假设您始终使用窗口进行测试,则可以使用 window.scrollY :

window.onscroll = function (event) 
{
if(this.scrollY > 1000)
{
alert('xxxxxxxxxxx');
}
}

jsFiddle Demo

关于javascript - 如何获取页面滚动位置(y轴),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21435037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com