gpt4 book ai didi

javascript - Chrome 和 IE : parallax (jQuery animate) is not smooth when using mouse wheel to scroll

转载 作者:数据小太阳 更新时间:2023-10-29 04:06:18 25 4
gpt4 key购买 nike

我改编了 this 为我的网站使用视差效果的 jQuery 插件。问题是(即使在上面链接中的演示中)Chrome 和 IE 的滚动真的不流畅。只有当您按下鼠标中键并且滚动是连续的(不是“逐步的” "当您滚动鼠标滚轮时)。所以当你使用鼠标滚轮滚动时,视差效果就完全被破坏了。在 Firefox 中,即使使用鼠标滚轮滚动,滚动也是连续的。有没有一种方法可以在 IE 和 Chrome 中连续滚动(javascript?)。

Here是我的网站(如您所见,如果您使用 Firefox 访问它,效果完全不同)。

最佳答案

我用这个 jQuery 脚本解决了这个问题(它为键盘和鼠标滚动添加了 EventListener),希望它能有所帮助。 :)

if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

var time = 1300;
var distance = 270;

function wheel(event) {
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;

handle();
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}

function handle() {

$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time);
}


$(document).keydown(function (e) {

switch (e.which) {
//up
case 38:
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - distance
}, time);
break;

//down
case 40:
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() + distance
}, time);
break;
}
});

关于javascript - Chrome 和 IE : parallax (jQuery animate) is not smooth when using mouse wheel to scroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18563802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com