Giter VIP home page Giter VIP logo

Comments (7)

Stanko avatar Stanko commented on July 22, 2024 1

Thanks for the suggestions!
I applied it and released 1.3.17.

Can you please give it a go?

from react-plx.

AlexandraKlein avatar AlexandraKlein commented on July 22, 2024 1

So much smoother! Thanks so much! 🔥

from react-plx.

Stanko avatar Stanko commented on July 22, 2024 1

Nice! Thanks for help!

from react-plx.

Stanko avatar Stanko commented on July 22, 2024

Hello @AlexandraKlein,

This is how library works - on scroll, it calculates interpolated value of the property it needs to animate.

In your example, image is scaled a lot (300%) for a duration of window height. Meaning that when you scroll for something like 50px, it is 1/20 of the window height (if we assume window height is 1000px) which means the image is going to be scaled for (end-start) * 1 / 20 which in this specific case comes to (300% - 100%) * 1 / 20 = 10%. So the image gets scaled for 10% which is obvious and choppy. On top of that resizing images on scroll is expensive as well.

That's why trackpad scrolling works much better than the mouse scroll.

For this specific case, try using position: fixed, as it works pretty smoothly for me (Safari 14.0.3):

Mar-21-2021.19-06-31.mp4

I had an idea of adding a super short transition, but that isn't trivial to implement, and I never invested time.

Hope that helps, cheers!

from react-plx.

AlexandraKlein avatar AlexandraKlein commented on July 22, 2024

Thanks for taking a look, @Stanko!

However, I used a large scale value to demonstrate the choppiness, but it's choppy even going from scale(1) to scale(1.1). Again, this is most noticeable on Safari. Seems that this should not require a position: fixed to solve.

plx-scale-scroll.mp4

from react-plx.

Stanko avatar Stanko commented on July 22, 2024

Honestly, not sure why it happens, it probably has something with browser recalculating the image's position on scroll as well as scaling it.

from react-plx.

AlexandraKlein avatar AlexandraKlein commented on July 22, 2024

It's this line: https://github.com/Stanko/react-plx/blob/master/source/Plx.js#L387

For pixel values, it works fine, but for scale is choppy because it's only going to 2 decimals. Would you consider changing this to return value.toFixed(4);(or return Math.floor(value * 10000) / 10000;)?

Also, may I suggest adding newStyle.willChange = 'transform'; inside this condition? https://github.com/Stanko/react-plx/blob/master/source/Plx.js#L452 (ref: https://dev.opera.com/articles/css-will-change-property/)

from react-plx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.