【问题标题】:Detect Reached the top of div from the bottom检测从底部到达div的顶部
【发布时间】:2015-11-11 08:14:50
【问题描述】:

我如何检测用户何时从底部滚动到某个 div 的顶部。

我试过了:

    var pos = $("#hotspotdiv").offset();
    $(window).scroll(function() {

        if ($(window).scrollTop()>=pos.top){
          console.log("Reached DIV:");
        }
});

但“到达的 DIV:”仅在 div 位于屏幕一半时才会回显。

【问题讨论】:

  • 尝试使用$("#hotspotdiv").position().top
  • 请在 jsFiddle 上重现您的问题..

标签: jquery html css


【解决方案1】:

工作小提琴:http://jsfiddle.net/jbaeh0La/

尝试以下解决方案:

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    if (scroll===0){
        alert("Reached DIV:");
    }
});

【讨论】:

  • 如果您提供一些 HTML 代码或 JSFiddle,我可以为您提供更多帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 2011-12-04
  • 1970-01-01
  • 2012-06-01
  • 2011-10-14
  • 1970-01-01
相关资源
最近更新 更多