如何知道用户何时滚动经过

发布于 2024-11-09 13:59:53 字数 261 浏览 5 评论 0原文

我正在构建一些东西,向用户展示他们没有见过的物品。

每个项目都在

中,因此当用户滚动经过 div 或查看该 div 时,我希望将该项目标记为已查看。

谷歌阅读器就是这样做的,如果你滚动浏览提要中的某个项目,它会自动将其标记为已读。

如何追踪这一点?请指教。

注意:不应该仅限于使用鼠标滚动,向下/向上翻页,使用箭头键等也应该计算在内。主要标准是用户已经看到了 div。

I'm building something where I show users items that they haven't seen.

Each item is in a <div>, so when the user scrolls past a div, or views the div, I want that item to be marked as having been seen.

Google reader does this, if you scroll past an item in your feed there it automatically marks it as read.

How can this be tracked? Advice please.

Note: It shouldn't be restricted to using the mouse to scroll, hitting page down/up, using arrow keys, etc should also be counted. The main criteria is that the user has seen a div.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坏尐絯℡ 2024-11-16 13:59:53

您需要 jQuery 的 scrollTop

例如:

$(window).scrollTop() > $('#mydiv').offset().top;

当它第一次进入视图时,或者如果您希望它在完全视图中时被标记,则将 $('#mydiv').height() 添加到顶部偏移量。

You need jQuery's scrollTop.

Something like:

$(window).scrollTop() > $('#mydiv').offset().top;

for when it first comes into view, or add $('#mydiv').height() to the top offset if you want it to be marked when it's fully in view.

末蓝 2024-11-16 13:59:53

您可以使用这样的解决方案,http://www.appelsiini.net/projects/viewport,我以前用过。

或者查看其他解决方案:检测窗口中呈现的 div 以实现类似 Google Reader 的自动标记为已读?

You could use a solution like this, http://www.appelsiini.net/projects/viewport, which I used in the past.

Or see this for other solutions: Detecting divs as rendered in the window to implement Google-Reader-like auto-mark-as-read?

半夏半凉 2024-11-16 13:59:53

看看$("#divid").scrollTop()

Have a look at $("#divid").scrollTop().

兔姬 2024-11-16 13:59:53

我想你会需要这样的东西......

$(window).scroll(function(){
    var scroll = $(this).scrollTop();
    var vieweditems = $('div').filter(function(){
       return scroll> $(this).offset().top;
       //compare the div's offset top with the window scroll position 
       // this returns the collection of viewed divs
    })// this object is colleection of viewd divs
      .removeClass('hilight')
      //Remove the class which distinguishes the unread and read items
      .map(function(){
          return this.id.split('_')[1];
      }).get();
      //This is the collection of ids of viewd divs
      //vieweditems  now holds the ids of viewed divs

});

I think you'll need something like this...

$(window).scroll(function(){
    var scroll = $(this).scrollTop();
    var vieweditems = $('div').filter(function(){
       return scroll> $(this).offset().top;
       //compare the div's offset top with the window scroll position 
       // this returns the collection of viewed divs
    })// this object is colleection of viewd divs
      .removeClass('hilight')
      //Remove the class which distinguishes the unread and read items
      .map(function(){
          return this.id.split('_')[1];
      }).get();
      //This is the collection of ids of viewd divs
      //vieweditems  now holds the ids of viewed divs

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文