简体   繁体   English

选择要使用 jQuery 设置动画的元素时,AOS(滚动动画)库不起作用

[英]AOS (animate on scroll) library not working when selecting elements to animate with jQuery

I'm trying to animate H1 elements for many pages using AOS (animate on scroll).我正在尝试使用 AOS(滚动动画)为许多页面设置 H1 元素的动画。 I have several pages that use the title so I'm selecting all the titles with jQuery.我有几个使用标题的页面,所以我用 jQuery 选择了所有的标题。 If I type in the attributes manually in each title it works, but not when adding them through jQuery.如果我在每个标题中手动输入属性,它会起作用,但在通过 jQuery 添加它们时不起作用。 I have selected other elements with jQuery to animate them and they do work.我用 jQuery 选择了其他元素来为它们设置动画,它们确实有效。 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();
 });

 <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); });

您应该将其附加到标题中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM