Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choppy scrolling in Safari

I have a problem with my micro website. When I scroll, it's nice and smooth in all browsers except Safari. When I do scroll in Safari, the content div jumps or moves frequently (it should stay in place) and makes the scrolling look choppy. Do you have any idea what could be wrong?

This is the website:
http://beta.dynamicdust.com

like image 784
Dominik Hadl Avatar asked Jun 11 '14 07:06

Dominik Hadl


People also ask

Why is my scrolling so choppy?

You may have a problem with a system setting or a graphics driver if you experience choppy scrolling on Web pages. The choppy page display could mean that your computer's touch device or mouse is set at too high of a scrolling interval or that the computer's graphics card isn't able to process graphics fast enough.

Why is scrolling not smooth on Mac?

The reason could be related to Apple's variable refresh rate implementation, to conserve battery life by using a lower rate. Apple should offer an option for users to enable ProMotion in Safari. Let us know if this solution worked to make web scrolling smoother for you on your 2021 MacBook Pro.


2 Answers

I haven't checked to see how my answer compares to Jack's, but I think the problem is that Safari attempts to be very power efficient. As a result, it is hesitant to enable hardware acceleration unless it needs to. A common trick that people use to force hardware acceleration is to place -webkit-transform: translate3d(0, 0, 0); into the css for the divs which are moving. I tried it with the content class and it seemed a little better. You might try applying it to the other layers as well.

EDIT: I applied it to the left and right text holder divs as well, and the page seems just as smooth as Chrome now.

like image 189
Kevin Flansburg Avatar answered Oct 11 '22 10:10

Kevin Flansburg


I took a look and did see the "choppy" scrolling you mentioned (looking at it more, it was hit or miss - sometimes it was smooth, other times it was VERY choppy).

It seems you've got some performance issues with your parallax callback on Safari (though it wouldn't surprise me if it's some buggy implementation with Safari...)

One thing I would recommend is taking a look at requestAnimationFrame for webkit. For a test, I wrapped the logic to update the offsets in a raf (and cached the window.pageYOffset value) and it seemed smoother on my end.

function parallax(e) {
    window.webkitRequestAnimationFrame(function() {
        var offset = window.pageYOffset;
        a.style.top = (offset / 2) + "px";
        b.style.top = (offset / 2) + "px";
        textbox.style.top =- (offset * 0.7) + "px";
        textbox2.style.top =- (offset * 0.7) + "px";
    });
}

To be honest, you could probably use raf for all browsers (if they support it).

Another trick people use when animating elements is to accelerate the layer that the element you are animating is on. There are a few ways to do this, but the easiest is to use -webkit-transition and set translateZ(0). It wouldn't hurt to add the two additional lines as well:

-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;

Also, I noticed that some elements you offset (using style) are position: relative - Personally, I'd say that any element that's to be animated should be position: absolute. This will remove the element from the DOM, and offsetting it won't cause reflows to surrounding elements (which may contribute to your choppiness).

Edit - one other thing I noticed is that "choppiness/weirdness" happens when you encounter rubberbanding on safari (my guess are the negative values). That might be something you'll want to look at as well.

Good luck!

like image 40
Jack Avatar answered Oct 11 '22 11:10

Jack