简体   繁体   English

如何在滚动时触发SVG动画?

[英]How to trigger an SVG animation on scroll?

So I've finally cracked SVG animations (totally through cheating) and like most sites that use them if they're halfway down the page they begin automatically and you miss it, so how is it possible to trigger the animation on scroll to that div container? 因此,我终于破解了SVG动画(完全通过作弊),并且像大多数使用它们的网站一样,如果它们位于页面的中途,它们会自动开始并且您会错过它,因此,如何在滚动到该div时触发动画容器?

Any help would be great, 任何帮助都会很棒,

Thanks! 谢谢!

You can use 您可以使用

beginElement() function to starts animations manually. beginElement()函数可手动启动动画。

for this to work, you have to set the begin attribute of animate element to indefinite 为此,您必须将animate元素的begin属性animateindefinite

a simple example would be something like 一个简单的例子就是

window.onscroll = function(){
  var anime= document.getElementsByTagName('animate')[0];
  // check for the amount of scroll
  anime.beginElement();
}

You could also make use of beginElementAt() 您还可以利用beginElementAt()

read more about svg Animation Timing Control 阅读有关svg动画定时控制的更多信息

side note: Can't be more accurate since you haven't shared much info or code samples, and not sure what you meant by 'cheating' 旁注:由于您没有共享太多信息或代码示例,并且不确定“作弊”的含义,因此无法更准确

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

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