Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将javascript addEventListener从';车轮';至';滚动';_Javascript_Jquery_Addeventlistener - Fatal编程技术网

将javascript addEventListener从';车轮';至';滚动';

将javascript addEventListener从';车轮';至';滚动';,javascript,jquery,addeventlistener,Javascript,Jquery,Addeventlistener,我试图将此javascript事件更改为在滚动而不是鼠标滚轮上发生。我试过换衣服 window.addEventListener('wheel',function (e) 到 然后在这条线上改变 var scrollVal = e.deltaY * 0.001; 到 但它仍然不起作用。这是完整的代码: window.addEventListener('wheel',function (e) { if(!parallaxLocked){ var scrollVal = e.deltaY

我试图将此javascript事件更改为在滚动而不是鼠标滚轮上发生。我试过换衣服

window.addEventListener('wheel',function (e)

然后在这条线上改变

var scrollVal = e.deltaY * 0.001;

但它仍然不起作用。这是完整的代码:

window.addEventListener('wheel',function (e) { 
if(!parallaxLocked){
  var scrollVal = e.deltaY * 0.001;

  introContentDist -= (scrollVal * (window.innerHeight * 0.2));
  mainContentDist -= (scrollVal * window.innerHeight);

  if(mainContentDist < window.innerHeight){
    if(mainContentDist > 0){
      var distanceCoveredPercentage = mainContentDist / window.innerHeight;
      TweenMax.to(introDiv, 0.1, {y: introContentDist+"px", opacity: 1 * distanceCoveredPercentage}); 
      TweenMax.to(belowFold, 0.1, {y: mainContentDist+"px"}); 
      window.scrollTo(0,0); 

      if(!firstSlideFadedUp){
        if(mainContentDist < window.innerHeight * 0.5){ // if parallaxed up 50%
          contentSections[0].className = 'airpoints-module -active'; // fade in first section
        }
      }

      if(!stickyLogosFadedUp){
        if(mainContentDist < window.innerHeight * 0.25){ // if parallaxed up 75%
          stickyLogo.className = 'c-sticky-logo fade-in'; // fade in sticky logo changer
          stickyLogosFadedUp = true;
        }
      }
    } else {
      // when scrolled to end, lock divs to final place
      TweenMax.to(introDiv, 0.1, {y: "-30%"+"px"}); 
      TweenMax.to(belowFold, 0.1, {y: "0%"});
      parallaxLocked = true;

      // now that everything is locked in place
      setupScrollLogoChanger(); 
    }
  }
}
});
window.addEventListener('wheel',函数(e){
如果(!视差锁定){
var scrollVal=e.deltaY*0.001;
introContentDist-=(scrollVal*(window.innerHeight*0.2));
mainContentDist-=(scrollVal*window.innerHeight);
if(mainContentDist0){
var distanceCoveredPercentage=mainContentDist/window.innerHeight;
TweenMax.to(introDiv,0.1,{y:introContentDist+“px”,不透明度:1*distanceCoveredPercentage});
TweenMax.to(低于0.1倍,{y:mainContentDist+“px”});
滚动到(0,0);
如果(!firstSlideFadedUp){
if(mainContentDist
滚动事件上没有
scrollTop
属性。您可以使用
窗口。改为滚动
。看

示例:

您可以使用
$(窗口)。关闭('wheel')
$(窗口)。打开('scroll',函数(e){/*您的代码*/})
var scrollVal = e.scrollTop * 0.001;
window.addEventListener('wheel',function (e) { 
if(!parallaxLocked){
  var scrollVal = e.deltaY * 0.001;

  introContentDist -= (scrollVal * (window.innerHeight * 0.2));
  mainContentDist -= (scrollVal * window.innerHeight);

  if(mainContentDist < window.innerHeight){
    if(mainContentDist > 0){
      var distanceCoveredPercentage = mainContentDist / window.innerHeight;
      TweenMax.to(introDiv, 0.1, {y: introContentDist+"px", opacity: 1 * distanceCoveredPercentage}); 
      TweenMax.to(belowFold, 0.1, {y: mainContentDist+"px"}); 
      window.scrollTo(0,0); 

      if(!firstSlideFadedUp){
        if(mainContentDist < window.innerHeight * 0.5){ // if parallaxed up 50%
          contentSections[0].className = 'airpoints-module -active'; // fade in first section
        }
      }

      if(!stickyLogosFadedUp){
        if(mainContentDist < window.innerHeight * 0.25){ // if parallaxed up 75%
          stickyLogo.className = 'c-sticky-logo fade-in'; // fade in sticky logo changer
          stickyLogosFadedUp = true;
        }
      }
    } else {
      // when scrolled to end, lock divs to final place
      TweenMax.to(introDiv, 0.1, {y: "-30%"+"px"}); 
      TweenMax.to(belowFold, 0.1, {y: "0%"});
      parallaxLocked = true;

      // now that everything is locked in place
      setupScrollLogoChanger(); 
    }
  }
}
});
window.addEventListener('scroll', function (e) { 
    if(!parallaxLocked){
        var scrollVal = window.scrollY * 0.001;
        ...