最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AOS (animate on scroll) library not working when selecting elements to animate with jQuery - Stack Overflow

programmeradmin3浏览0评论

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="/[email protected]/dist/aos.css" rel="stylesheet">
 <script src="/[email protected]/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();
 });

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./[email protected]/dist/aos.css" rel="stylesheet">
 <script src="https://unpkg./[email protected]/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();
 });
Share Improve this question edited May 14, 2019 at 22:16 charlesFromSoCal asked May 14, 2019 at 20:22 charlesFromSoCalcharlesFromSoCal 471 gold badge1 silver badge6 bronze badges 2
  • Try to move AOS.init(); to window on load. Also remove aos.refresh from window load. – u238 Commented May 14, 2019 at 20:37
  • That did not fix it. – charlesFromSoCal Commented May 14, 2019 at 20:42
Add a ment  | 

2 Answers 2

Reset to default 0

<link href="https://unpkg./[email protected]/dist/aos.css" rel="stylesheet">
<script src="https://unpkg./[email protected]/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);
});

You should append this to the header:

<script type="text/javascript">jQuery(document).ready(function($){$(function() {      AOS.init(); });  });  </script>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论