Comments (7)
Thanks for the suggestions!
I applied it and released 1.3.17
.
Can you please give it a go?
from react-plx.
So much smoother! Thanks so much! 🔥
from react-plx.
Nice! Thanks for help!
from react-plx.
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.
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.
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.
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)
- Run independent animation after scroll reaches an element
- TypeScript types HOT 4
- Scrolling On IE Edge browser jumping and moving Plx divs HOT 1
- react-plx and superposed html elements HOT 1
- Showcase: <antoniocosentino.com> HOT 2
- I have a page with the same component - the scroll position is always related to the first child HOT 4
- Set `end:` as pixel-difference to `start` ? HOT 1
- Act only on Sub-Elements of the Parallax HOT 2
- Choppy animation
- use react-plx inside svg HOT 4
- Strange flipping on mobile-devices while scrolling HOT 6
- dropped fps HOT 3
- Smoother effect using values with more decimals HOT 2
- Is there a way to sequence from previous values? HOT 5
- Set fixed position when element is centered? HOT 2
- onPlxStart/ onPlxEnd function not running in right moment? HOT 2
- Possibility to add html <tag> prop back in? HOT 6
- End the animation when the element leaves the viewport HOT 2
- Using Plx with multiple React components HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-plx.