简体   繁体   English

Anime.js-在事件上结合时间线和动画

[英]Anime.js - Combining timeline and animation on event

I would like to run an animation on click, after the timeline runs. 我想在时间轴运行后点击运行动画。 But I can't get it to work. 但是我无法正常工作。 The timeline runs fine, but the onclick animation doesn't. 时间轴运行良好,但onclick动画却不能。 Any idea on how to get this to work properly? 有关如何使其正常工作的任何想法?

HTML: HTML:

<section id="step-1">
  <h1 class="ml3">Title</h1
  <a href="#" class="next-step">Next Step</a>
</section>

JS: JS:

$( document ).ready(function() {

  // Wrap every letter in a span
  $('.ml3').each(function(){
    $(this).html($(this).text().replace(/([^\x00-\x80]|\w)/g, "<span class='letter'>$&</span>"));
  });

  var timelineStep1 = anime.timeline({loop: false});

  timelineStep1
    .add({
      targets: '.ml3 .letter',
      opacity: [0,1],
      easing: "easeInOutQuad",
      duration: 2250,
      delay: function(el, i) {
        return 100 * (i+1)
      }
    })
    .add({
      targets: '.next-step',
      opacity: [0,1],
      easing: "easeInOutQuad",
      duration: 2250,
      /*delay: function(el, i) {
        return 150 * (i+1)
      }*/
    });

  var nextStep = anime({
    targets: '#step-1',
    opacity: 0,
    duration: 2250,
    easing: "easeInOutQuad",
    autoplay: false
  });

  $('#step-1 .next-step').click(function(e){
    e.preventDefault();
    nextStep.play;
  });

});

You have a typo in your classname of your <a> tag 您的<a>标签的类名中有错字

<section id="step-1">
  <h1 class="ml3">Title</h1
  <a href="#" class="next-step">Next Step</a>
</section>

That should work! 那应该工作!

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

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