Jquery 检测向下滚动时禁用向下滚动

Jquery 检测向下滚动时禁用向下滚动,jquery,html,Jquery,Html,我在我的网站上有一个简单的欢迎页面,上面显示了一张图片,还有标题和注册按钮 工作小提琴: $(document).ready(function() { var CurrentScroll = 0; $(window).scroll(function(event){ var NextScroll = $(this).scrollTop()

我在我的网站上有一个简单的欢迎页面,上面显示了一张图片,还有标题和注册按钮

工作小提琴:

        $(document).ready(function() { 

                      var CurrentScroll = 0;
                      $(window).scroll(function(event){

                          var NextScroll = $(this).scrollTop();

                          if (NextScroll > CurrentScroll){
                             //write the codes related to down-ward scrolling here
                             /// Animations Codes Here

                          }
                          else {
                             //write the codes related to upward-scrolling here

                          }

                          CurrentScroll = NextScroll;  //Updates current scroll position
                      });
                    });
问题:我希望能够在检测任何向下滚动事件时禁用页面滚动

这是因为我希望能够在向下滚动事件上执行一些动画,而不是页面实际滚动

尝试:

        $(document).ready(function() { 

                      var CurrentScroll = 0;
                      $(window).scroll(function(event){

                          var NextScroll = $(this).scrollTop();

                          if (NextScroll > CurrentScroll){
                             //write the codes related to down-ward scrolling here
                             /// Animations Codes Here

                          }
                          else {
                             //write the codes related to upward-scrolling here

                          }

                          CurrentScroll = NextScroll;  //Updates current scroll position
                      });
                    });
这是我试图检测向下滚动的脚本,但由于滚动而看不到动画,因此我需要一种解决方法

如何使用jquery实现我想要的

body
{
  position: fixed; 
  overflow-y: scroll;
  width: 100%;
  height: 100%
}

试试这个

简单的方法就是简单地监听滚动事件,忘记试图阻止滚动,然后为用户接管滚动,如下所示:

var scrollTarget = 300;
$("#divThatScrolls").scroll(function() {
    $("#divThatScrolls").animate({ scrollTop: scrollTarget+"px" });
});

只需根据您要滚动到的位置更改
scrollTarget

您的代码中有语法错误。为什么使用
})3次?当向下滚动时,它应该是您想要的动画的两倍?我希望能够在动画发生@niravjoshiw时禁用页面的滚动,而此代码可能会回答问题,提供有关如何和/或为什么解决问题的附加信息,以提高答案的长期价值。记住,你是在将来回答读者的问题,而不仅仅是现在提问的人!请在回答中添加解释,并说明适用的限制和假设。提到为什么这个答案比其他答案更合适也没什么坏处。