jQuery mobile-用户滚动到特定元素时触发事件

时间:2018-07-18 11:12:16

标签: javascript jquery html scroll

我正在尝试检测用户何时滚动到类$('select[name="select1"]').change(function(){ ....... }) 的特定div元素 但是.seller-info方法始终返回0

我已经在这里尝试了所有示例,但是仍然无法正常工作。 这是我最新的解决方案:

scrollTop()

任何想法我该如何检测到它?

1 个答案:

答案 0 :(得分:0)

我认为它对您有帮助

$(window).scroll(function() {
   var hT = $('#scroll-to').offset().top,
       hH = $('#scroll-to').outerHeight(),
       wH = $(window).height(),
       wS = $(this).scrollTop();
    console.log((hT-wH) , wS);
   if (wS > (hT+hH-wH)){
     alert('scroll reached!');
   }
});
div {
    height:400px;
    background:green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Scroll Down</div>
<h1 id="scroll-to">I am The H1</h1>