Replies: 1 comment 3 replies
-
Great that you found a solution! Never used butter, but what happens if you only ever run the init code once and not repeat the init step on every contentReplaced event? Should be the same as continually cancelling and restarting. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I am making a website where I implemented Swup as well as Butter.js for smooth scrolling on my website.
I ran into a very strange issue.
Basically, here is how I initialize my Butter.js script :
var options = {
wrapperId: 'butter',
wrapperDamper: 0.01,
cancelOnTouch: true
};
The "wrapperDamber" option basically determines the speed of scroll smoothnes, the lower the number is, the longer the animation will be for smooth scroll. This part of code also runs every time swup.on('contentReplaced') happens.
Here is my issue :
When I go from my index.html page to, for example, shop.html, and then maybe return to index.html, my smooth scrolling animation will be a little faster. Each time I repeat this, the smooth scrolling animation will be faster and faster until its not even smooth scroll animation, its just a regular scroll. I tried commenting out the swup code, and everything works fine then.
I understand that probably not many people used butter.js, but does anyone have some idea on why this is happening or how I can fix it ? :)
Thank you so very much for any answers.
EDIT :
I solved it !!!
If anyone runs into this issue, here is how I solved it.
In my script, I added this code :
swup.on('willReplaceContent', function() {
butter.cancel();
});
This basically destroyed the current instance of my butter script, and this event happens before "contentReplaced".
So you can just destroy the instance of your plugin inside swup.on('willReplaceContent'), and then re-initialize it inside swup.on('contentReplaced').
Beta Was this translation helpful? Give feedback.
All reactions