2017-05-31 66 views
0

我不太確定如何用文字描述這個;但我打算做的事情就像本網站所取得的成果:http://sapia.com.pe/滾動到jQuery或JavaScript的具體位置?

當您向下滾動時,它會將您帶到頁面的特定位置以及向上滾動。我如何使用JQuery來做到這一點?是否需要任何插件?

+2

您鏈接該網站使用:https://github.com/alvarotrigo/fullPage.js – naslund

回答

1

檢查代碼片段低於它會給你基本思路如何才能實現

,或者您可以使用插件,像fullpage

var arr = ['_a','_b','_c']; 
 
var i=0; 
 
var doing=false; 
 
$(window).bind('mousewheel', function(e){ 
 
     if(e.originalEvent.wheelDelta > 0) { 
 
      if(i==-1) i=2; 
 
      if(!doing){ 
 
      $('html, body').animate({ 
 
        scrollTop: $("#"+arr[i--]).offset().top 
 
       }, 600,function(){doing=false;}); 
 
      doing=true; 
 
      } 
 
     } 
 
     else{ 
 
      if(i==3) i=0; 
 
      if(!doing){ 
 
      $('html, body').animate({ 
 
        scrollTop: $("#"+arr[i++]).offset().top 
 
       }, 600,function(){doing=false;}); 
 
      doing=true; 
 
      } 
 
     } 
 
});
body{ 
 
    overflow: hidden; 
 
} 
 
.section,html,body{ 
 
    width:100%; 
 
    height:100%; 
 
} 
 
.a{ background-color:red; } 
 
.b{ background-color:yellow; } 
 
.c{ background-color:blue; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="_a" class="section a"></div> 
 
<div id="_b" class="section b"></div> 
 
<div id="_c" class="section c"></div>