Javascript 停止滚动容器末尾的Div

Javascript 停止滚动容器末尾的Div,javascript,jquery,html,scroll,jquery-animate,Javascript,Jquery,Html,Scroll,Jquery Animate,我正在创建一个电视指南,并实现了“上一个”和“下一个”按钮以滚动到下一个小时数。但是,当我单击此按钮时,滚动是连续的,没有终点。有没有办法在某一特定点上阻止这种情况?i、 e每个小时单元为100px,因此24x100=2400px,滚动应停止在该单元。我用于此目的的jquery如下所示: $(文档).ready(函数(){ var$item=$('.timeCell.cellProgram'), 可见=2, 指数=0, endIndex=($item.length/visible)-1; $('

我正在创建一个电视指南,并实现了“上一个”和“下一个”按钮以滚动到下一个小时数。但是,当我单击此按钮时,滚动是连续的,没有终点。有没有办法在某一特定点上阻止这种情况?i、 e每个小时单元为100px,因此24x100=2400px,滚动应停止在该单元。我用于此目的的jquery如下所示:

$(文档).ready(函数(){

var$item=$('.timeCell.cellProgram'),
可见=2,
指数=0,
endIndex=($item.length/visible)-1;
$('div#arrowR')。单击(函数(){
如果(索引0){
索引--;
$item.animate({'left':'+=246px'});
}
});
}))


非常感谢您的帮助:)

您应该使用
$selector.offset().top
$selector.outerHeight()
来获取容器的底部位置。 然后添加EventListener滚动事件,以检查当前位置是否与您的条件匹配

例如:

 var $selector = $('.class-selector');
 if($selector.length == 0) {
    return;
 }
 var triggerPosition = $selector.offset().top + $selector.outerHeight(); // position of container's bottom

 $(window).on('scroll', function(){
      var windowTopPosition = $(window).scrollTop()
        , windowBottomPosition = windowTopPosition  + $(window).height(); // depend on your idea, use the top or bottom as currentPosition
     var currentPosition = windowBottomPosition' // in this i.e, I use the bottom.

     if( currentPosition > triggerPosition) {
           // trigger if those bottom meet each other , such as:
           stopScroll();
     } else { 
          // trigger when windows is above the container's bottom, such as:
          continuousScroll(); 
     }
  });
希望能有帮助

 var $selector = $('.class-selector');
 if($selector.length == 0) {
    return;
 }
 var triggerPosition = $selector.offset().top + $selector.outerHeight(); // position of container's bottom

 $(window).on('scroll', function(){
      var windowTopPosition = $(window).scrollTop()
        , windowBottomPosition = windowTopPosition  + $(window).height(); // depend on your idea, use the top or bottom as currentPosition
     var currentPosition = windowBottomPosition' // in this i.e, I use the bottom.

     if( currentPosition > triggerPosition) {
           // trigger if those bottom meet each other , such as:
           stopScroll();
     } else { 
          // trigger when windows is above the container's bottom, such as:
          continuousScroll(); 
     }
  });