我正在使用stellar.js
插件处理视差网站。问题在于它使卷轴“抖动”。
我设法使用scrollTo
和TweenMax
插件的组合在桌面浏览器上修复它:
$(function(){
var $window = $(window); //Window object
var scrollTime = 1.2; //Scroll time
var scrollDistance = 170; //Distance. Use smaller value for shorter scroll and greater value for longer scroll
$window.on("mousewheel DOMMouseScroll", function(event){
event.preventDefault();
var delta = event.originalEvent.wheelDelta/120 || -event.originalEvent.detail/3;
var scrollTop = $window.scrollTop();
var finalScroll = scrollTop - parseInt(delta*scrollDistance);
TweenMax.to($window, scrollTime, {
scrollTo : { y: finalScroll, autoKill:true },
ease: Power1.easeOut, //For more easing functions see http://api.greensock.com/js/com/greensock/easing/package-detail.html
autoKill: true,
overwrite: 5
});
});
});
它非常完美,但在平板电脑和智能手机上问题仍然存在,因为mousewheel DOMMouseScroll
不是设备事件。不知道如何为这些设备解决这个问题?