2

I'm trying to animate H1 elements for many pages using AOS (animate on scroll). I have several pages that use the title so I'm selecting all the titles with jQuery. If I type in the attributes manually in each title it works, but not when adding them through jQuery. I have selected other elements with jQuery to animate them and they do work. The tile is at the very top of each page.Thanks!

 <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
 <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>

 <h1 class="title"> </h1>

 $(document).ready(function () {
    $('.title').attr({
       "data-aos": "zoom-in",
       "data-aos-duration": "2000"
    });

    AOS.init();
 });

 //refresh animations
 $(window).on('load', function() {
    AOS.refresh();
 });
charlesFromSoCal
  • 37
  • 1
  • 1
  • 6

2 Answers2

0

<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>

<h1 class="title"> </h1>

$(document).ready(function () {
    $('.title').attr({
        "data-aos": "zoom-in",
        "data-aos-duration": "2000"
    });
    setTimeout(() => {
        AOS.init();
    }, 120);
});
-1

You should append this to the header:

<script type="text/javascript">jQuery(document).ready(function($){$(function() {      AOS.init(); });  });  </script>
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 1
    Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. [From Review](/review/late-answers/27116225) – double-beep Sep 08 '20 at 17:58