jQuery滚动力不会滚动超过450px

jQuery scrolling force won't scroll more than 450px

本文关键字:滚动 450px jQuery      更新时间:2023-12-09
//Scroll Status abfragen}
$(window).scroll(function(){
    var wScroll = $(this).scrollTop();


$("#vor").click(function() {
    if(wScroll < 450) { 
    $('html, body').animate({
        scrollTop: 450
    }, 2000);
    }
    if(wScroll < 1900 & wScroll > 450 ) { 
    $('html, body').animate({
        scrollTop: 1900
    }, 2000);
    }
 });
    });//wScroll

当我单击图标时会发生什么 #vor 它会滚动到 450,但在动画结束后我无法滚动超过 450px。 不是用手/鼠标,也不是通过点击 我是新手,但我试图解决这个问题这么久,但找不到办法......感谢您的帮助!

编辑顺便说一句。以下代码为:

$("#pfeil").click(function() {
$('html, body').animate({
    scrollTop: 450 }, 2000);
});

它工作得很好。问题必须出在wSroll功能上。

它会调用您的作业数百次,因为您在每次滚动时都会分配点击事件,因此它们只是不断加起来。它不会锁定您的滚动,而是没有完成它必须运行的所有功能。

将其更改为以下内容:3 次编辑,删除 var,添加结束 }(;并删除最后一个 }(;

//Scroll Status abfragen}
$(window).scroll(function() {
  wScroll = $(this).scrollTop(); //Get rid of var, so it can be used by functions outside of this function.
}); // That's all the work we need to do.



$("#vor").click(function() {
  console.log('Called');
  if (wScroll < 450) {
    $('html, body').animate({
      scrollTop: 450
    }, 2000);
  }
  if (wScroll < 1900 & wScroll > 450) {
    $('html, body').animate({
      scrollTop: 1900
    }, 2000);
  }
});

https://jsfiddle.net/gregborbonus/dke33uyk/3/