Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重新生成网格时仅运行一次CSS动画_Javascript_Html_Css_Css Animations - Fatal编程技术网

Javascript 重新生成网格时仅运行一次CSS动画

Javascript 重新生成网格时仅运行一次CSS动画,javascript,html,css,css-animations,Javascript,Html,Css,Css Animations,Draw_flex()函数在表单提交时运行,因此每次提交新容器时,动画都会再次运行。如何使它只运行一次?您可以在函数的开头查找div.container元素draw\u flex:如果该元素存在,则向“my flex container”添加一个no animation类 div.container { background: url('notebg.png') no-repeat; height: 250px; animation-duration: 4s; animation-name

Draw_flex()函数在表单提交时运行,因此每次提交新容器时,动画都会再次运行。如何使它只运行一次?

您可以在函数的开头查找
div.container
元素
draw\u flex
:如果该元素存在,则向“my flex container”添加一个
no animation

div.container {

background: url('notebg.png') no-repeat;

height: 250px;

animation-duration: 4s;
animation-name: fadeIn;  
}
而CSS就变成了

function draw_flex() {

   if (document.querySelectorAll('#my-flex div.container').length > 0) {   
       document.getElementById('my-flex').classList.add('no-animation');
   } 
   ...
}

因此,在第一次调用
draw\u flex
功能后,动画将被禁用。

hi@AntonSusman,您是否尝试过下面的代码?
function draw_flex() {

   if (document.querySelectorAll('#my-flex div.container').length > 0) {   
       document.getElementById('my-flex').classList.add('no-animation');
   } 
   ...
}
div.container {
   background: url('notebg.png') no-repeat;
   height: 250px;
}

#my-flex:not(.no-animation) div.container {
   animation-duration: 4s;
   animation-name: fadeIn;  
}