如何使用jQuery检测页面的滚动位置

编程入门 行业动态 更新时间:2024-10-20 11:38:15
本文介绍了如何使用jQuery检测页面的滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在网站上遇到jQuery功能问题。它的作用是,它使用 window.scroll()函数来识别窗口何时改变其滚动位置,并且在更改时调用一些函数来加载来自服务器。

I am having trouble with jQuery functionality on my website. What it does, is that it uses the window.scroll() function to recognize when the windows changes its scroll position and at the change calls a few functions to load data from the server.

问题是只要有一点变化就会调用 .scroll()函数在滚动位置并在底部加载数据;但是,我希望实现的是当滚动/页面位置到达底部时加载新数据,就像Facebook Feed一样。

The problem is the .scroll() function is called as soon as there is even a little change in the scroll position and loads data at the bottom; however, what I wish to achieve is to load new data when the scroll/page position reaches at the bottom, like it happens for Facebook feed.

但我不确定如何使用jQuery检测滚动位置?

But I am not sure how to detect scroll position using jQuery?

function getData() { $.getJSON('Get/GetData?no=1', function (responseText) { //Load some data from the server }) }; $(window).scroll(function () { getData(); });

推荐答案

您可以使用jQuery的 .scrollTop() method

You can extract the scroll position using jQuery's .scrollTop() method

$(window).scroll(function (event) { var scroll = $(window).scrollTop(); // Do something });

更多推荐

如何使用jQuery检测页面的滚动位置

本文发布于:2023-10-08 01:35:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   位置   页面   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!