-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating Scroll height on page change #31
Comments
I had the same problem using Barba.js. You need to destroy the instance of the plugin using scroll.destroy(); and initialize it every time a page is loaded. |
Hi, I don't know if it helps you since its vuejs related but I've written a mixin which calls update() and destroy() method on $route() change. Could be simple to adapt for vanilla and react I guess... Relevant Parts are in export default {
watch: {
$route() {
console.log("route changed: ", this.$route);
this.lmS.update();
}
},
mounted() {
this.$nextTick(
function() {
this.lmS = new this.locomotiveScroll({
el: document.querySelector("#js-scroll"),
smooth: true /* if false disable overflow: hidden on html, body */
});
}.bind(this)
);
},
destroyed() {
this.lmS.destroy();
},
}; Here is a Sandbox Demo, which handles also scroll and resize events |
On our projects each page has its own instance of LS. We destroy the LS instance of the page we are leaving, and we instantiate a new one on the page we are entering. You can also use the |
hey @patchampoux and @Jerek0 , how exactly did you do that? can you show us the code? i am struggling too using barba.js.. thank you so much |
@jarovision The lines you want to look at are 21 to 28 and 651. This is using barba v2. Hope it helps. |
I had this issue with a React application (specifically Gatsby). In my class-based component I just had it like: componentDidMount() {
this.scroll = new LocomotiveScroll({
el: document.querySelector("body"),
smooth: true,
})
)
componentWillUnmount() {
this.scroll.destroy()
} |
Thank you so much. I managed now. Have a good life. :)
…
On 12. Feb 2020, at 23:56, Lewis Menelaws ***@***.***> wrote:
I had this issue with a React (specifically Gatsby). In my class-based component I just had it like:
componentDidMount() {
this.scroll = new LocomotiveScroll({
el: document.querySelector("body"),
smooth: true,
})
)
componentWillUnmount() {
this.scroll.destroy()
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hi there, Before opening a new issue I was wondering how you guys handle updating the scroll instance when using components like accordions or animations that affect the height of the scroll container? I know this question is in reference to routing but attaching scroll.update to click events does not seem to do anything? If anybody has an example that would be great. |
@Mulegoat: Calling Also, please update LS to |
Thank you @Jerek0 - I'm managing to successfully call update now. The container resizes when it's height changes perfectly 99% of the time, at first sticky items did not maintain their position - note to anyone else experiencing this - remove any top, bottom or position sticky css on data-sticky elements :). Quick question, how do you normally go about writing functions that need to access LS? Do you place them all in global scope in the setTimeout function as per the demo? Lets say I had multiple different funcitons for ajaxing content, accordions etc, would you attach a single callback function that only calls scroll.update() to all these kinds of functions? I have another question regarding Intersection Obserever but will open a new thread if I cannot figure it out for myself. Many thanks again Jeremy, and congrats to everyone at Locomotive for the recent awards. Richly deserved! |
It's really up to you and how you like to work. You can store your LS instance globally to access it from anywhere, or you can setup a custom event listener linked to LS that you can call from anywhere as well. At Locomotive we use modularorg/modularjs which has its own system for calling methods bewteen modules (e.g. E.g. this.scroll.on('scroll', (args) => {
window.yournamespace.scroll.state = args
}) Thanks for the kind words 🙏 The whole team is really proud of this achievement and we'll continue to do our best to deliver high quality work! |
Sorry to open this one up again but I am working through this browser resize issue I am having - sounds exactly like this issue. I'm still a bit of a javascript newbie though... I understand that the LS scroll instance has to be updated, but how do I run this when the browser window is resized? edit by @Jerek0 : follow up on #112 (comment) |
HI there, I try to do the below on my code but did not work pls help on the code.
|
You can look at this page, it is well documented : https://barba.js.org/docs/advanced/third-party/#Locomotive-scroll |
Hi @patchampoux Are you sure this version is using Barba v2? I can't seem to get it working with v2, but v1 seems to work ok. Just curious if this is a typo or something I'm probably doing wrong :) |
Yes, this is a typo, sorry. |
Hey, First, thank you for your library! I have the same issue and even if i call "update" after the modularLoad ready event, my new page don't have the right height. I have to resize manually and that's ok. Do you have an idea ? |
I'm having this same issue using Swup for page transitions. Basically where the height of the transitioned page with locomotive initialized doesnt allow the user to scroll all the way down/content is cutoff. One note I've noticed if I refresh the page again the issue is fixed and I can scroll the whole thing. Anyone know how to get this working with Swup specifically, is it similar to the barba instructions here: https://barba.js.org/docs/advanced/third-party/#Locomotive-scroll ? Mostly looking for some more specific code for this - like how to destroy the LS instance of the page we are leaving and instantiating a new one on the page we are entering. And where that should live in my function? Obviously a noob at this btw but your time and thoughts are much appreciated!
|
@HunterHolthaus I was able to resolve this doing the following:
|
We are using Locomotive Scroll (LS) on a site that utilizes a page transition plugin. When we transition to a new page sometime LS doesn't allow the user to scroll all the way down. I'm guessing this has something to do with the page not fully loaded when LS is initialized. From what I can tell, the Locomotive site is similar. How do you all get around this obstacle. Any insights would be highly appreciated!
The text was updated successfully, but these errors were encountered: