ScrollMagic icon indicating copy to clipboard operation
ScrollMagic copied to clipboard

Pin Jitter on Safari and Firefox

Open jessicaleyland8 opened this issue 11 years ago • 29 comments

I am trying to pin multiple sections to the top of page one after the other. Like your simple pinning example. This works fine on chrome but on safari and firefox whilst the section is pinned and you scroll it causes a jitter which ruins the smooth flow of the page completely. Any ideas why this could be?

jessicaleyland8 avatar Mar 03 '15 11:03 jessicaleyland8

I just want to reinforce that I see this too. On the sticky elements demo page I see jitter in Firefox 36.0.

drwlrsn avatar Mar 03 '15 17:03 drwlrsn

I am having similar issues since upgrading to 2.0. In Firefox and Safari (OS X 10.10.2), elements inside a pinned element experience rather severe jitter while scrolling. It seems to be more pronounced if the element is tweened in vertically, rather than horizontally. But it is still jittery if tweened in horizontally.

Screencast

discern avatar Mar 04 '15 19:03 discern

I'm here to confirm that I am seeing this as well, seems more pronounced on firefox, although definitely still present on safari as well

austinhulak avatar Mar 07 '15 22:03 austinhulak

Possible duplicate of #247 #218 #186 #167

krnlde avatar Mar 08 '15 15:03 krnlde

I also found the same problem in firefox 36.0 since I upgraded to version 2.0

pvmsikrsna avatar Mar 09 '15 16:03 pvmsikrsna

1.3 wfm, but upon upgrading to 2.0.0, I'm now getting this behavior.

This is a regression, not a dupe of #186 or #167 as they refer to a safari specific problem on an older scrollmagic.

lamtha avatar Mar 09 '15 18:03 lamtha

If you need a workaround until it gets fixed, try commenting out lines 1892–1904 in scrollmagic/uncompressed/ScrollMagic.js.

This solved it for me, but your mileage may vary. I am still, however, having a separate, and very severe rubber band issue in IE11 only.

var
fixedPos = _util.get.offset(_pinOptions.spacer, true),
    // get viewport position of spacer
    scrollDistance = _options.reverse || _options.duration === 0 ? containerInfo.scrollPos - _scrollOffset.start // quicker
    : Math.round(_progress * _options.duration * 10) / 10; // if no reverse and during pin the position needs to be recalculated using the progress
// add scrollDistance
fixedPos[containerInfo.vertical ? "top" : "left"] += scrollDistance;
// set new values
_util.css(_pin, {
    top: fixedPos.top,
    left: fixedPos.left
});

discern avatar Mar 09 '15 18:03 discern

I'm seeing this too, running Firefox 36 on OSX 10.10.2. Pinned elements experience severe jitter while scrolling. This was not a problem on 1.3.0, and arose when I upgraded the page to 2.0.0.

bennet-org avatar Mar 09 '15 19:03 bennet-org

@discern Your temporary fix works in firefox when the elements are pinned to the top of the viewport but not when they are offset from that top.

pvmsikrsna avatar Mar 10 '15 06:03 pvmsikrsna

Good to know. Yes, I was experiencing the issue within a pinned, full-viewport scene. It's just a temporary workaround for limited cases. Hopefully, @janpaepke or another contributor can will come up with a permanent solution.

discern avatar Mar 10 '15 14:03 discern

Commenting out lines 1892–1904 broke the centered pinned effect for me, so I tried something else and it seemed to fix it. I moved that block into the previous if statement that executes if the pinned element is being switched back to its fixed position:

// pinned state
if (_util.css(_pin, "position") != "fixed") {
    // change state before updating pin spacer (position changes due to fixed collapsing might occur.)
    _util.css(_pin, {
        "position": "fixed"
    });
    // update pin spacer
    updatePinDimensions();

    var
    fixedPos = _util.get.offset(_pinOptions.spacer, true),
        // get viewport position of spacer
        scrollDistance = _options.reverse || _options.duration === 0 ? containerInfo.scrollPos - _scrollOffset.start // quicker
        : Math.round(_progress * _options.duration * 10) / 10; // if no reverse and during pin the position needs to be recalculated using the progress
    // add scrollDistance
    fixedPos[containerInfo.vertical ? "top" : "left"] += scrollDistance;

    // set new values
    _util.css(_pin, {
        top: fixedPos.top,
        left: fixedPos.left
    });
}

It seems that the problem is that block is updating the fixed position EVERY time you scroll which is causing the jittery behavior. If someone can confirm that this fixes the issue in their case as well, I'll go ahead and make a pull request.

mark-youssef avatar Mar 10 '15 22:03 mark-youssef

@unireverse Can confirm that your fix works for me too - moving that block into the previous IF statement prevents the jittery behaviour in both Firefox 36 and Safari 8.0.3. Thanks!

bennet-org avatar Mar 11 '15 07:03 bennet-org

Sorry for the delayed answer, I was on holidays...

The position needs to be updated, because in some cases it may change (parent elements, resizing or pinning elements within containers – it should move with dom, if window is scrolled, but be fixed, if container is scrolled).

In theory if nothing changes the result of the calculation should always be the same and no jitter occur. I remember struggling with this on version 1 as well, So I'm sure I'll be able to figure it out here...

I'll try to get on it asap.

janpaepke avatar Mar 11 '15 09:03 janpaepke

@unireverse Your move works for me. Tested on Safari 5.1.7, IE 11 , and Firefox 36.0. But what I observed is a little jump before the element gets pinned on these browsers. No issues on Chrome.

pvmsikrsna avatar Mar 11 '15 12:03 pvmsikrsna

Welcome back to the fray, @janpaepke!

This works in my situation as well. I, too, am getting the jump (with our without this fix), and it is extremely severe (but off-topic) in IE 11. In other browsers it is minimal, but noticeable. Thanks!

discern avatar Mar 11 '15 13:03 discern

@janpaepke I see what you mean. The position does need to be updated. I found a bug with my fix where the pinned element gets misplaced if the user scrolls too fast in my case.

mark-youssef avatar Mar 11 '15 17:03 mark-youssef

So it turns out this was something I originally first observed quite a while ago: http://stackoverflow.com/questions/25685608/why-is-an-interval-function-executed-before-an-event-callback

Apparently because of the loose way browsers handle the scroll event callbacks sometimes there is a discrepancy between the time ScrollMagic updated the scroll position (onscroll) and when it actually updates the scenes (on rAF). This discrepancy only occurs when using a trackpad or a mouswheel, not when using the scrollbar. So it's basically something that happens because of the internal implementation of smooth scroll or inertia inside of browsers.

The obvious solution is to also update the scroll position on rAF, right before the scenes are updated. This solves the pin jitter in FF and potentially also resolves some issues raised regarding parallax jitters (at least for me it does).

I will release an update soon.

Please confirm: Does this solve the pin jitter for FF for you? Does this solve the pin jitter in IE for you? Does this resolve the parallax jitter in FF/IE?

janpaepke avatar Mar 17 '15 12:03 janpaepke

New version is released: https://github.com/janpaepke/ScrollMagic/releases/tag/v2.0.1

Let me know if that does anything. :)

janpaepke avatar Mar 17 '15 13:03 janpaepke

I can confirm this solves the pin jitter in FF/IE for me. Thanks!

mark-youssef avatar Mar 17 '15 17:03 mark-youssef

Great solution. It worked on Firefox(Win/Mac) in my virtual machine. Thanks.

tomothumb avatar Mar 19 '15 05:03 tomothumb