Giter VIP home page Giter VIP logo

Comments (5)

Stanko avatar Stanko commented on July 20, 2024

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.

andy-hook avatar andy-hook commented on July 20, 2024

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.

Stanko avatar Stanko commented on July 20, 2024

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.

andy-hook avatar andy-hook commented on July 20, 2024

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.

Stanko avatar Stanko commented on July 20, 2024

You are welcome, glad it worked!

from animated-scroll-to.

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.