I used a different approach to achieve animated scrolling, see live working fiddle
wheel scroll, , , , ? wheel , , .
. data-prev="sec1" data-next="sec2" , . window.height, , , $(document).scrollTop(), , , .
HTML-:
<body>
<section id="sec1"></section>
<section id="sec2"></section>
<section id="sec3"></section>
<section id="sec4"></section>
<section id="sec5"></section>
</body>
javascript:
$(function() {
var isScrolling = false;
$(window).on('wheel', function(e) {
if (!isScrolling){
isScrolling = true;
var howFarFromTop = $(document).scrollTop();
var currentWindowHeight = $( window ).height();
var delta = e.originalEvent.deltaY;
var currentSlide = Math.floor(howFarFromTop / currentWindowHeight);
if (delta > 0){
smoothScroll(currentWindowHeight * (currentSlide + 1));
}
else {
smoothScroll(currentWindowHeight * (currentSlide -1));
}
setTimeout(function(){isScrolling = false}, 400)
}
return false;
});
});
function smoothScroll(offsetPixels){
if (offsetPixels < 0){
offsetPixels = 0;
}
$('html, body').animate({
scrollTop: offsetPixels
}, 300);
}
source
share