aos icon indicating copy to clipboard operation
aos copied to clipboard

Animation triggers only when resize the browser

Open OhhConti opened this issue 6 years ago • 15 comments

This is:

  • Bug

Specifications

  • AOS version: 2.3.1
  • OS: windows
  • Browser: chrome

Expected Behavior

Animations should work fine

Actual Behavior

Animations are triggered only when I resize the browser

Steps to Reproduce the Problem

Detailed Description

Possible Solution

Does the bug depend on overflow property? How should I set overflow's value? Does the bug may be caused by the material design lite library? (I'm using it --> https://getmdl.io/started/index.html)

OhhConti avatar Nov 25 '18 18:11 OhhConti

Having this same issue.

andyshokry avatar Dec 13 '18 06:12 andyshokry

me too

nadavtal avatar Dec 13 '18 13:12 nadavtal

I had issues with this too. Solved it by calling AOS.refresh() as soon as user starts scrolling.

let scrollRef = 0;

window.addEventListener('scroll', function() {
  // increase value up to 10, then refresh AOS
  scrollRef <= 10 ? scrollRef++ : AOS.refresh();
});

Not exactly an ideal solution, but at least it seems to be working. I chose the value 10 arbitrarily, executing the refresh after only 1 was glitchy (if user was scrolling while page was loading, etc).

pestbarn avatar Jan 03 '19 12:01 pestbarn

more information about html structure would be nice. codepen as example with the issue. if you dont provide informations to reproduce the issue we can only guess...

i think you scoll an element and not the body itself. so probably related to #223

if so you can resolve the issue with a little bit of code: https://github.com/michalsnik/aos/issues/223#issuecomment-420336772 strongly recommended to debounce this solution.

MarioPerini avatar Jan 10 '19 16:01 MarioPerini

Playing off @pestbarn's comment, I was able to solve mine, by using AOS.refresh() after a small timeout to avoid adding any event listeners. setTimeout(() => {AOS.refresh();}, 500);

Also just a side-note, my issue started after I added lazy loading to my images

Dan2D avatar Nov 19 '19 16:11 Dan2D

I had issues with this too. Solved it by calling AOS.refresh() as soon as user starts scrolling.

let scrollRef = 0;

window.addEventListener('scroll', function() {
  // increase value up to 10, then refresh AOS
  scrollRef <= 10 ? scrollRef++ : AOS.refresh();
});

Not exactly an ideal solution, but at least it seems to be working. I chose the value 10 arbitrarily, executing the refresh after only 1 was glitchy (if user was scrolling while page was loading, etc).

Thank you very much, I got mine issue fixed with your method

hello-myc avatar Feb 13 '20 05:02 hello-myc

Finally solved this issue by calling refresh method inside scroll listener on parent container . For angular, add below code in app.component.ts -> ngOnInit()

$(".parent-container").on('scroll', function () {
      AOS.refresh();
 });

rajesh4295 avatar Apr 05 '20 19:04 rajesh4295

Worked

I had issues with this too. Solved it by calling AOS.refresh() as soon as user starts scrolling.

let scrollRef = 0;

window.addEventListener('scroll', function() {
  // increase value up to 10, then refresh AOS
  scrollRef <= 10 ? scrollRef++ : AOS.refresh();
});

Not exactly an ideal solution, but at least it seems to be working. I chose the value 10 arbitrarily, executing the refresh after only 1 was glitchy (if user was scrolling while page was loading, etc).

Works, thanks so much!

adampatterson avatar Sep 15 '20 06:09 adampatterson

Playing off @pestbarn's comment, I was able to solve mine, by using AOS.refresh() after a small timeout to avoid adding any event listeners. setTimeout(() => {AOS.refresh();}, 500);

Also just a side-note, my issue started after I added lazy loading to my images

I had the same issue, which I believe is also caused by lazy loading the images.
the setTimeout solution works, and as @Dan2D further mentioned, (I feel) it is the better solution as you don't have the expense of an eventListener.

d8nieldonaldson avatar Feb 24 '21 14:02 d8nieldonaldson

Playing off @pestbarn's comment, I was able to solve mine, by using AOS.refresh() after a small timeout to avoid adding any event listeners. setTimeout(() => {AOS.refresh();}, 500);

Also just a side-note, my issue started after I added lazy loading to my images

I have a NextJs application, where do I put this code to make it work properly ?

AashishSinghal avatar Aug 21 '21 06:08 AashishSinghal

let scrollRef = 0;

window.addEventListener('scroll', function() {
  // increase value up to 10, then refresh AOS
  scrollRef <= 10 ? scrollRef++ : AOS.refresh();
});

this did not work for me when I placed this code in my react nextjs app inside the _app.js file inside the React.useEffect function Please share how.

AashishSinghal avatar Aug 21 '21 07:08 AashishSinghal

If you are using React and encounter this problem, in my case, it is due to the fact that the website scrolling was happening in .App component and not the body tag. So what I did to fix it is the following:

App.js

import AOS from "aos";
import "aos/dist/aos.css";

useEffect(() => {
    AOS.init();

    //give <div className='App'> an id
    document.getElementById("app").addEventListener("scroll", () => {
    AOS.refresh();
    });
}, []);

MounirEl-Abbas avatar Dec 14 '21 20:12 MounirEl-Abbas

Playing off @pestbarn's comment, I was able to solve mine, by using AOS.refresh() after a small timeout to avoid adding any event listeners. setTimeout(() => {AOS.refresh();}, 500);

Also just a side-note, my issue started after I added lazy loading to my images

Super elegant and efficient, it worked for me! The transitions were buggy before browser resize, this fixed that.

FrancescoDiCursi avatar Jul 16 '22 22:07 FrancescoDiCursi

it will not work if the element your scrolling from not the body!! for example : you have an main TAG inside your HTML and it's the one you're scrolling from it won't work! only the body

anasbehhari avatar Oct 30 '22 17:10 anasbehhari

Playing off @pestbarn's comment, I was able to solve mine, by using AOS.refresh() after a small timeout to avoid adding any event listeners. setTimeout(() => {AOS.refresh();}, 500);

Also just a side-note, my issue started after I added lazy loading to my images

✅ You are the best, simple, directly to the point, works for me in React app! Thank you bro

kbcruz6 avatar Dec 07 '22 14:12 kbcruz6