I'm developing a parallax scrolling website using the Stellar and Skrollr libraries. The website behaves perfectly in Firefox because of Firefox's smooth scrolling feature, but in Chrome, scrolling with the mouse wheel is jerky, and the parallax effect is almost ruined. Is there any way to get the smooth scrolling with the mouse wheel in all browsers while maintaining performance?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Simplr-SmoothScroll have one bug - it is not working with body, when body height is not auto.
I found another plugin and it is became perfect solution for me. https://github.com/inuyaksa/jquery.nicescroll
download library (demo) and add to the begining
Basically scroll causes jerky because of repaints and reflows. if you can check and reduce those reflows you might get the scroll performance.
and check the onScroll event callback function whether its executing any expensive logic . and are there any memory leakage.
Chrome developer tool bar heap snap shot will be useful for detecting memory leaks and to see repaints and reflows.
I had not a lot of time, but I tried to write a (cross browser & dirty) smooth scrolling functionality on the fly. When you stop scrolling it smoothly decelerates. You can rewrite it a little bit so it fits your needs.
Give it a try here:
Smooth scrolling:
http://jsfiddle.net/ubawR/4/
I found two jQuery plugins that may do what you want.
Simplr-SmoothScroll // Source: SE Question
jQuery SmoothWheelHope this helps.
edit: Struck out SmoothWheel because of comments - it hasn't been updated in ages, and SmoothScroll seems well maintained.
for chrome only try this - https://github.com/im4aLL/chromeSmoothScroll only 1 KB
If you are Cargo cult programmer, go with jQuery. Proceed only if you are Real programmer.
Screw jQuery.animate(), understand the math behind and pick an algorithm. Robert Penner has a nice demo, I picked EaseOutQuad.
Read how to handle mouse wheel cross-browser style here, then do some more reading.
In this code, I choose not to support IE 8 and older. The idea is to hook up the wheel event, prevent it (since the default behavior is jerky jump) and perform own smooth jump
As you can see in this demo, I prefer as little easing as possible, just to avoid jerky scrolling. Read the comments above and design your own scrolling which suits your project.
Note: mousewheel also hooks to touchpad, but not to up/down keys. You should consider to hook key events, too.