Comments (5)
Hey @andy-hook,
I recently started version 2, and one of things I will add is optional custom easing. I am playing with an idea of including multiple easings to choose from, but I'm afraid of bloating a library.
I plan to release v2 in next week or two.
Cheers!
EDIT: If it is crucial for you to get it asap, easing happens here:
https://github.com/Stanko/animated-scroll-to/blob/master/animated-scroll-to.js#L126-L128
It should be fairly easy to replace it with the custom function.
from animated-scroll-to.
Thanks for getting back so quickly. I was attempting to modify this line earlier but seem to run into issues with unintended scroll jumping, if you have a spare moment do you think you could provide me a code example using a different curve? or how I might plug in a common ease eg: https://gist.github.com/gre/1650294
I know you must be busy but this would be a huge help for me. Thank you.
from animated-scroll-to.
No worries, but thanks for being considerate.
I think I actually used those functions when I was writing the first version 🙂
Anyway I used easeOutCubic
easeOutCubic: function (t) { return (--t)*t*t+1 },
Note that (--t)
changes t
in place, which I did in the line above.
var t = (timeDiff / duration) - 1;
var easing = t * t * t + 1;
var scrollPosition = Math.round(initialScrollPosition + (diff * easing));
So to use any of these functions change the code to this:
var t = (timeDiff / duration); // remove -1
// copy any easing from the site
// easeInOutCubic: function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 },
var easing = t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1;
var scrollPosition = Math.round(initialScrollPosition + (diff * easing));
I just tried this, and it seems to work, let me know if you made it.
from animated-scroll-to.
Oh! it was the - 1 that I was forgetting to remove from the previous line.
Would be great to be able to pass this custom curve via an opt in version 2 depending on how you approach this, for now I'll use my fork but will switch to an NPM import for version 2.
Thanks again man, much appreciated.
from animated-scroll-to.
You are welcome, glad it worked!
from animated-scroll-to.
Related Issues (20)
- Can you update the CHANGELOG.md for v2? HOT 1
- V2 - Cannot find module 'animated-scroll-to' from 'scrollTo.js' HOT 1
- Switching to commonjs instead of es2015 HOT 2
- v2 breaks SSR apps HOT 4
- Typescript typings are out of date and not stored in the the repo HOT 6
- can you remove comment script tag HOT 4
- Compatible with react HOT 9
- Limit scroll directions HOT 1
- No trigger HOT 4
- OnComplete option is not available since v2 HOT 4
- Remove "@types/node" dependency
- Compile Error on node 14 HOT 3
- wrong dependency? HOT 3
- Add note about scroll-behaviour: smooth to readme HOT 3
- [Feature] Add support for iframe contentWindow HOT 1
- It don't work on my mobile applications HOT 4
- Set default options during import HOT 4
- Using with Typescript and useRef hook throws a type error HOT 2
- [feature] add support for scroll-to element and locate it from bottom HOT 1
- Speed can't be changed HOT 3
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 animated-scroll-to.