简体   繁体   English

在滚动时,当元素垂直居中时添加内联CSS

[英]On scroll add inline CSS when element is vertically centred

I have an SVG with CSS animated elements. 我有一个带有CSS动画元素的SVG。 Using animation-play-state I am keeping them at paused, with jQuery or JavaScript I would like to change that to running only once the SVG has been centred vertically on scroll. 使用动画播放状态,我将它们暂停,使用jQuery或JavaScript,我想将其更改为仅在SVG垂直居中滚动时才运行。

My idea was to grab the class .paused which keeps them all paused and overwrite it with the aforementioned inline CSS. 我的想法是抓住.paused类,使它们全部暂停并用上述内联CSS覆盖它。

You could achieve your requirement by adding two different css classes. 您可以通过添加两个不同的CSS类来实现您的要求。

.classA_animate{
   animation: animation_1 2s linear infinite;
}

Once you have reached a scroll location remove classA_animate and add classB_animate 到达滚动位置后,删除classA_animate并添加classB_animate

.classB_animate{
   animation: animation_2 2s linear infinite;
}

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

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