第一個問題: 找不到爲什麼.animate線性減速到達目標點時。 我錯過了什麼?線性緩動減慢
奇怪的是,從中間圖片向上它總是完美的作品(只在這種情況下)。
第二個問題: 有沒有辦法在動畫正在進行時禁止用戶滾動?
[編輯] 我已經切出照片,以便更容易調試 [/編輯]
$(document).ready(function(){
\t var scrollCheck = 0;
\t var heightVal = window.innerHeight;
\t \t \t
\t \t \t
\t $(window).resize(function(){
\t window.scroll(0,0);
\t heightVal = window.innerHeight;
\t hControl1 = heightVal -1;
\t scrollCheck = 0;
\t });
\t var isScrolling = false;
\t \t
\t window.addEventListener("scroll", throttleScroll, false);
\t \t \t \t
\t function throttleScroll(e) {
\t if (isScrolling == false) {
\t window.requestAnimationFrame(function() {
\t scrolling(e);
\t isScrolling = false;
\t //console.log("Scrolling");
\t });
\t }
\t isScrolling = true;
\t }
\t \t \t \t
\t document.addEventListener("DOMContentLoaded", scrolling, false);
\t
\t function scrolling(e) {
\t var yValue = $(window).scrollTop();
\t \t \t \t \t
\t //1st photo, scroll down
\t if (yValue > 0 && scrollCheck === 0){
\t \t \t \t \t \t
\t $('body').stop().animate({scrollTop:heightVal}, 700, 'linear');
\t if (window.pageYOffset === heightVal){
\t scrollCheck = 1;
\t //console.log(window.pageYOffset);
\t }
\t }//2nd photo, scroll up
\t else if(yValue < heightVal && scrollCheck === 1 ){
\t \t \t \t \t \t
\t $('body').stop().animate({scrollTop:(-heightVal)}, 700, 'linear');
\t if (window.pageYOffset === 0){
\t scrollCheck = 0;
\t }
\t }//2nd photo, scroll down
\t else if(yValue > heightVal && scrollCheck === 1){
\t $('body').stop().animate({scrollTop:(heightVal*2)}, 700, 'linear');
if (window.pageYOffset === (heightVal*2)){
\t scrollCheck = 2;
\t }
\t }//3rd photo, scroll up
\t else if(yValue < heightVal*2 && scrollCheck === 2){
$('body').stop().animate({scrollTop:(heightVal)}, 700, 'linear');
\t \t if (window.pageYOffset === heightVal){
\t \t scrollCheck = 1;
\t \t }
\t }
}//end of scrolling(e) funcion
}); //end of $(document).ready
html,body{
margin: 0;
height: 100%;
width: 100%;
}
#section1,#section2,#section3{
height: 100%;
width: 100%;
vertical-align: top;
}
#section1{
background-color: grey;
}
#section2{
background-color: green;
}
#section3{
background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='section1'></div>
<div id='section2'></div>
<div id='section3'></div>
你能在stacksnippets重現問題? – guest271314
@ guest271314我會盡力去做 – playinThrouLife
@ guest271314 嗯,恐怕我不知道你實際要求什麼,我去了stacksnippet.com,雖然我沒有看到有任何選項添加/編輯任何東西 – playinThrouLife