aos icon indicating copy to clipboard operation
aos copied to clipboard

Css scroll snap compatibility

Open seb-celinedesign opened this issue 6 years ago • 19 comments

This is:

  • Bug

Specifications

  • AOS version: 2.3.4
  • OS: MacOS
  • Browser: Chrome, Firefox and Safari 12.0

Expected Behavior

When i use the css scroll-snap-type: mandatory, aos-animate class must be added to the node

Actual Behavior

aos-animate class is NOT added to the node and animation are not triggered

Steps to Reproduce the Problem

  1. Put this css on a container
height: 100vh;
overflow-y: scroll;
scroll-snap-points-y: repeat(100vh);
scroll-snap-destination: 0 0;
scroll-snap-type: y mandatory;
scroll-snap-type: mandatory;

This css on child :

scroll-snap-align: start;
height: 100%;
  1. Install aos
  2. And add data-aos="fade-up" on the childs
  3. AOS animation doesn't trigger

seb-celinedesign avatar Mar 14 '19 12:03 seb-celinedesign

Does anyone else know how to fix this issue? I'm facing the same problem as well. Is there any event to hook?

huanyichuang avatar Oct 20 '19 08:10 huanyichuang

I have the exact same issue. Did anyone find a hack to fix or a real fix for this incompatibility? I have a codepen with this implemented that demonstrates the bug here: https://codepen.io/Julianoe/pen/PoqbWmm

This issue will soon be one year old. Anyone?

Julianoe avatar Feb 26 '20 15:02 Julianoe

having the same issue here, with no workaround so far.

vphilot avatar Mar 18 '20 20:03 vphilot

Also just came across this issue.

dlewand691 avatar Apr 03 '20 13:04 dlewand691

This is working for me so far. It requires you to add .aos class to any element you're animating. It didn't seem to work with the .aos-init class, probably because that's added from the JS.

const aosAnimation = document.querySelectorAll('.aos');
observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.intersectionRatio > 0) {
      entry.target.classList.add('aos-animate');
    } else {
      entry.target.classList.remove('aos-animate');
    }
  });
});
aosAnimation.forEach(aosObject => {
  observer.observe(aosObject);
});

dlewand691 avatar Apr 03 '20 16:04 dlewand691

I'm not quite sure i'm understanding what you suggest. My code did not the .aos-init class to work to activate the animations on scroll. But once i add the scroll snap. Still not working :( I added the .aos class in my code but it does not change anything. Would you mind giving a fork of that codepen? Are you using AOS v2 ?

Julianoe avatar Apr 03 '20 19:04 Julianoe

facing the same issue.. does any one find out the solution?

saoud-ahmed-khan avatar Sep 13 '20 09:09 saoud-ahmed-khan

const aosAnimation = document.querySelectorAll('.aos'); observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add('aos-animate'); } else { entry.target.classList.remove('aos-animate'); } }); }); aosAnimation.forEach(aosObject => { observer.observe(aosObject); });

This works! however data-aos-offset is not working anymore. do you also know how to fix this?

evibreukers avatar Oct 20 '20 06:10 evibreukers

Having the same issue here. Anyone manage to resolve it? Using it with Gatsby.js

imshuffling avatar Dec 17 '20 11:12 imshuffling

In the end I used the fullpage.js library which got the scrolljack effect.

imshuffling avatar Dec 22 '20 12:12 imshuffling

having same issue .. i thought it may be because of using library so i tried getting scroll position , but not even getting the scroll position and also this function is not executing

document.body.onscroll = function (e) { var position = window.scrollY; console.log(position); }

Someone help!!

shivamsaksham avatar Jul 29 '21 05:07 shivamsaksham

Also having the same issue. does anyone have already a fix for this? huhu :(

cdcdianne avatar Oct 28 '21 20:10 cdcdianne

Added this and worked.

const aosAnimation = document.querySelectorAll('[data-aos]');
observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if (entry.intersectionRatio > 0) {
      entry.target.classList.add('aos-animate');
    } else {
      entry.target.classList.remove('aos-animate');
    }
  });
});
aosAnimation.forEach(aosObject => {
  observer.observe(aosObject);
});

rajilesh avatar Oct 29 '21 12:10 rajilesh

where to import the observer from on the solution in this sorry for being ignorant I am really new to this if someone please reply

const aosAnimation = document.querySelectorAll('[data-aos]'); observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add('aos-animate'); } else { entry.target.classList.remove('aos-animate'); } }); }); aosAnimation.forEach(aosObject => { observer.observe(aosObject); });

tohirul avatar Dec 06 '21 12:12 tohirul

Along with the code add the className in the tag of aos effect "aos-init aos-animate" these to tags on className and attach the code snippet is below in the component they should work on any project

const aosAnimation = document.querySelectorAll('[data-aos]'); observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add('aos-animate'); } else { entry.target.classList.remove('aos-animate'); } }); }); aosAnimation.forEach(aosObject => { observer.observe(aosObject); });

tohirul avatar Dec 06 '21 12:12 tohirul

aos doesnot work with overflow-y: scroll; property. If you want to use overflow property you need to refresh AOS on scroll of the window event, which can be triggered as

document.addEventListener('scroll', (event) => { AOS.refresh();}, {capture: true, passive: true,})

Note to pass capture property else event will not triggred on oveflow property.

Gokul1995 avatar Dec 17 '21 08:12 Gokul1995

This codepen worked fine for me. No other code needed.... https://codepen.io/fatty1996/pen/NWPjMdq

Csimpson avatar Apr 11 '22 18:04 Csimpson

Hii guys ,

i have found the solution . document.addEventListener('scroll', (event) => { const aosAnimation = document.querySelectorAll('[data-aos]'); observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add('aos-animate'); } else { entry.target.classList.remove('aos-animate'); } }); }); aosAnimation.forEach(aosObject => { observer.observe(aosObject); });}, {capture: true, passive: true,})

try this.

paste it in index.html in script tag before

PiyushAgrawal1243 avatar Jul 12 '22 07:07 PiyushAgrawal1243