小编Ice*_*000的帖子

window.scroll事件触发两次

无论我使用什么方法来检测页面上的滚动,事件都会被触发两次.请参阅我尝试过的不同方法的代码.

<body onmousewheel="alert('Why are you alerting twice?')">
Run Code Online (Sandbox Code Playgroud)

要么

<script src="js/jquery-1.8.3.min.js"></script>
<script>
$(window).scroll(function(){
    alert("Why are you alerting twice?");
});
</script>
Run Code Online (Sandbox Code Playgroud)

要么

window.onscroll = please_scroll;

function please_scroll() {
      alert("Why are you alerting twice?");
    }
Run Code Online (Sandbox Code Playgroud)

我甚至尝试过使用$ .debounce.

如果它有任何用处,我会解释我要做的事情:当用户向上或向下滚动滚轮时,页面会将滚动设置为下一个全宽度内容div的动画.我有一些代码可以成功地单击我的菜单,但我也希望它发生在用户滚动时,基本上是自动帮助他们滚动到我的页面的每个部分.这是我目前用于滚动的功能:

function scrollTo(id){
  // Scroll
  $('html,body').animate({scrollTop: $("#"+id).offset().top - 110},'slow',function(){
    animation_active = "false";
  });
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery scroll custom-scrolling

12
推荐指数
1
解决办法
8138
查看次数

标签 统计

custom-scrolling ×1

javascript ×1

jquery ×1

scroll ×1