简体   繁体   English

使用鼠标滚轮滚动时jQuery视差图像不平滑

[英]jQuery Parallax Image Not Smooth When Scrolling With Mousewheel

I have a site with a header image that I'm trying to use the parallax effect with. 我有一个带有标题图像的网站,试图与之一起使用视差效果。

I'm using the following JS to accomplish this: 我正在使用以下JS来完成此任务:

    $(window).scroll(function() {
       var scrolledY = $(window).scrollTop();
       $('#container').css('background-position', 'left ' +  ((scrolledY)) + 'px');
});

I used an example from this fiddle: http://jsfiddle.net/QN9cH/1/ 我用了这个小提琴的一个例子: http//jsfiddle.net/QN9cH/1/

This works great when scrolling down the page by clicking and dragging the scrollbar, however when I scroll with my mousewheel the image jumps around a lot and it's not smooth at all. 通过单击并拖动滚动条向下滚动页面时效果很好,但是当我用鼠标滚轮滚动时,图像会跳转很多并且根本不会平滑。

I've done a lot of research and have tried solutions such as the one here: Javascript - Smooth parallax scrolling with mouse wheel 我已经做了大量研究,并尝试了以下解决方案: Javascript-使用鼠标滚轮平滑视差滚动

However, I'm not able to get this working with my implementation. 但是,我无法使用我的实现。 I've tried several jquery libraries for smooth scrolling and haven't been able to get those to work properly either. 我已经尝试了多个jquery库来实现平滑滚动,但也无法使其正常运行。

Is there a way I can make scrolling with the mouse wheel act the same as if I were scrolling manually by clicking and dragging the scroll bar? 有没有一种方法可以使鼠标滚轮的行为与我通过单击并拖动滚动条进行手动滚动的行为相同?

This is not an answer (yet) but I've noticed that a large number of windows machines come with scroll wheels that "click", line-by-line, down the page. 这还不是答案(但是),但是我注意到大量的Windows机器都带有滚轮,这些滚轮可以在页面中逐行“单击”。

I'm not sure if this is the issue you are facing but all of those beautiful parallax effects that work really well with expensive mice and those super-smooth Apple trackpads and mice, but then suddenly shudder and look awful on stock windows mice. 我不确定这是否是您要面对的问题,但是所有这些美丽的视差效果在昂贵的鼠标以及那些超光滑的Apple触控板和鼠标上都能很好地发挥作用,但是突然摇晃起来,在普通的Windows鼠标上看起来很糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM