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
Reveal from bottom on scroll down and from top on scroll up #384
Comments
Hey Antonio, ScrollReveal presently has no built-in awareness of scroll direction. I think For what it's worth, I can point you to the correct part of the source to begin adding this functionality if you'd like to take a stab at forking the repository and creating a custom build. |
Hi Julian, |
PS: On a slightly separate note... too bad passing |
I can see why you want this behavior, the end result should look awesome. Edit: This is now baked-in since
|
Applying The Right AnimationsThis is the part I think it gets complicated to bake into ScrollReveal. I think instead, you'd want to use ScrollReveal just to track visibility and provide callbacks... but not to create/apply the styles automatically. Here is one way to do that: var noEffect = {
delay: 0,
distance: '0',
duration: 0,
easing: 'linear',
opacity: null,
origin: 'bottom',
rotate: { x: 0, y: 0, z: 0, },
scale: 1,
// container: this.defaults.container,
// desktop: this.defaults.desktop,
// mobile: this.defaults.mobile,
reset: true,
useDelay: 'always',
// viewFactor: this.defaults.viewFactor,
// viewOffset: this.defaults.viewOffset,
afterReset: function (el) {},
afterReveal: function (el) {},
beforeReset: function (el) {}, // fill me in
beforeReveal: function (el) {}, // fill me in
}
ScrollReveal().reveal('.items', noEffect)
. . . This If you create your own CSS animation/transition classes, you can apply them based on the container's direction property. Here’s an example of how you might implement those callbacks: var beforeRevealCallback = function (el) {
var id = el.getAttribute('data-sr-id')
var containerId = ScrollReveal().store.elements[id].containerId
var container = ScrollReveal().store.containers[containerId]
if (container.direction && container.direction.y > 0) {
el.classList.add('animateFromBottom')
} else {
el.classList.add('animateFromTop')
}
}
var beforeResetCallback = function (el) {
el.classList.remove('animateFromBottom')
el.classList.remove('animateFromTop')
} |
Now, I haven't tested this implementation all the way through, but this should hopefully give you a solid start at achieving the effect you'd like.
This is because instead of passing If you'd like, you can create a new issue to request that feature be added. If it can garner some community support, it could be possible to add support for something like |
Hey guys, I've been looking for the same thing, and have tried your code above @jlmakes and noticed a small bug which was forcing it to always add the class of
This works, however on first load before you scroll I get:
|
@sebszocinski Nice catch. I updated the pseudo code with: if (container.direction && container.direction.y > 0) {
el.classList.add('animateFromBottom')
} else {
el.classList.add('animateFromTop')
} Also, I've taking a second look at the commit though, and I'm not sure why I'll report back with why, or bump a new version with the fix. |
Whoa!!! :) |
@antoniocosta Nice! You're totally right about the undefined errors with |
Hey guys, Ive been able to achieve this affect with the following code: block1MedImgLeft()
function block1MedImgLeft() {
ScrollReveal().reveal('#block1-medImgLeft', { origin: 'bottom',
afterReveal: function () {
ScrollReveal().reveal('#block1-medImgLeft', { origin: 'top',
afterReveal: block1MedImgLeft
})
}
})
} This assumes the user will scroll down past |
@jlmakes Another refinement to your if statement there is to make it pick the correct direction on first load: if (container.direction) {
if (container.direction.y > 0) {
el.classList.add('animateFromBottom');
} else {
el.classList.add('animateFromTop');
};
} else {
if(el.getBoundingClientRect().top > 0) {
el.classList.add('animateFromBottom');
} else {
el.classList.add('animateFromTop');
};
}; |
This is awesome! Anyone have a working example? |
Quite old but try this example: https://jsfiddle.net/abmc/oaxmma6y/ |
Is it possible?
I have been fiddling but can't find a way to do it. I am guessing origin or distance would have to be reversed depending on scroll direction?
Please let me know... and thanks so much for the great work put into this!
The text was updated successfully, but these errors were encountered: