-
Notifications
You must be signed in to change notification settings - Fork 74
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
Child fixed container & smooth scrolling section container #58
Comments
Hi @atwaves, You'd like to have a fixed element inside the
From what I see, you're not extending the base class but directly using the default class import Smooth from 'smooth-scrolling'
export default class Custom extends Smooth {
constructor(opt) {
super(opt)
// pass extra HTMLElement to the options object
// and save them into the dom object of your Smooth instance
this.dom.section = opt.section
this.dom.child = opt.child
}
run() {
super.run()
// apply double transform to achieve a fixed position effect on the child element
this.dom.child.style[this.prefix] = this.getTransform(this.vars.current.toFixed(2))
this.dom.section.style[this.prefix] = this.getTransform(-this.vars.current.toFixed(2))
}
resize() {
// you will need to set this.vars.bounding again in the extended class
// just in case you want a different value for the scrolling bound
this.vars.bounding = this.dom.section.getBoundingClientRect().height - this.vars.height
super.resize()
}
} import Custom from '../smooth/custom'
const container = document.querySelector('.vs-container')
const child = document.querySelector('.vs-child')
this.smooth = new Smooth({
native: false,
noscrollbar: true,
section: container,
child: child,
ease: 0.15,
preload: true
})
this.smooth.init() I would just try to do the first option if you can (moving the fixed child element outside of the section) so you don't have to apply another transform. The Also, you don't need to pass in Let me know if that helps! |
don't work
I use react for rendering, this step will break dom constructing methodology |
Did you tried the second option then? |
Yes, I did. No effect |
Does the Let me know! |
No transforms applied, I will write clear example tomorrow. Thank you for support |
No problem! |
Hey guys, I would love to find out if anyone sorted this out. Looking to apply reversed transform to a child element for a sticky feel, and can't pull it out of the container, for visual purposes (elements passing in front of an below). |
Hi @23d1, would you be able to create a CodePen example of what you currently have? Let me know! |
Hey @baptistebriel, Unfortunately not, but here's my exact setup (as it relates to smooth-scrolling) in webpack;
It doesn't apply any transform inline styles to the .vs-sticky element(s). As a side note, I also have to add the smooth.init() into a setTimeout callback to make sure it captures all the content (typically skips a footer when setting the initial height of the .vs-scroll-view element on init). |
Hello @23d1 — Do you mean no transform at all is applied to If you're trying to apply a transform to a single element, use this.dom.sticky.forEach((el) => {
el.style[this.prefix] = this.getTransform(this.vars.current.toFixed(2))
}) Using a setTimeout is usually because your content height gets updated after all resize calculations have been made with smooth-scrolling. Check if there is any images that might take some time to load. You can try using |
@baptistebriel I couldn't for the life of me get that to work, any chance you could help me with a codepen or something? It's a much nicer solution, albeit "heavier" then what I ended up going with, which was simply getting the callback (but that only works for one direction right now, and could get convoluted pretty quickly when adding other directions... right?)... This is where I'm at now;
|
Hi. How to make child container fixed relative to window? Smooth scrolling container also is fixed.
And additionally: how to use listener?
The text was updated successfully, but these errors were encountered: