I've got a script that will allow for snap scrolling when you move down but I can't get it to allow the user to scroll back upwards.
var items = $(".item");
var animating = false;
$(window).scroll(function() {
clearTimeout($.data(this, 'scrollTimer'));
if (!animating) {
$.data(this, 'scrollTimer', setTimeout(function() {
items.each(function(key, value) {
if ($(value).offset().top > $(window).scrollTop()) {
animating = true;
$('body').animate( { scrollTop: $(value).offset().top + 'px' }, 1000);
setTimeout(function() { animating = false; }, 500);
return false;
}
});
}, 50));
}
});
You have to do
var body = $("html, body");
and
$(body).stop().animate( { scrollTop: $(value).offset().top)}, 1000,'swing');
Chrome reading body
and srolling, Firefox need html
to do it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.