2014-03-30 95 views
1

即時消息這個問題約2天左右,仍然找不到解決方案,所以我不得不在這裏..我有parallex網站,我想當用戶向下滾動(這一點是功能性的)時開始自動滾動整個網站,並且當用戶向上滾動時,自動滾動停止。但是,然後,當用戶再次向下滾動時,它應當以相同速度(相同超時)再次開始自動滾動beggining,但每次用戶向上和向下滾動,自動滾屏越來越快......jQuery/JS當用戶向上滾動並繼續向上滾動時,使自動滾動停止

這裏是我的代碼

<script> 
    var act = 0; 
    var y = 0; 
    var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x 
    $(window).bind(mousewheelevt, function(e){ 

     var evt = window.event || e //equalize event object  
     evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible    
     var delta = evt.detail ? evt.detail*(-40) : evt.wheelDelta //check for detail first, because it is used by Opera and FF 

     if(delta > 0) { 
      console.log('nahoru stop y=0 act=0'); 
      y = 0; 
      pageScrollStart(y); 
      act = 0; 
     } 
     else{ 

      if(act==1) 
      { 
       console.log('dolu aktivni nic'); 
      } 
      else 
      { 
       console.log('dolu neaktivni start y=1 act=1'); 
       y = 1; 
       pageScrollStart(y); 
       act = 1; 
      } 
      } 

    }); 
      function pageScrollStart() { 
       window.scrollBy(0,y); 
       scrolldelay = setTimeout('pageScrollStart()',50); 
      }; 

    </script> 

回答

0

解決..我只是不知道有關函數「clearTimeout」

所以現在看起來是這樣的:

 <script> 
    var act = 0; 
    var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x 
    $(window).bind(mousewheelevt, function(e){ 

     var evt = window.event || e //equalize event object  
     evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible    
     var delta = evt.detail ? evt.detail*(-40) : evt.wheelDelta //check for detail first, because it is used by Opera and FF 

     if(delta > 0) { 
      pageScrollStop(); 
      console.log('nahoru stop'); 
      act = 0; 
     } 
     else{ 
      if(act !== 1) 
      { 

       pageScrollStart(); 
       console.log('dolu start'); 
       act = 1; 
      } 
      } 

    }); 
      function pageScrollStart() { 
       window.scrollBy(0,1); 
       scrolldelay = setTimeout('pageScrollStart()',50); 
      }; 
      function pageScrollStop(){ 
       clearTimeout(scrolldelay); 
      } 
    </script> 
相關問題