【发布时间】:2018-08-11 11:55:34
【问题描述】:
有没有办法在不更改HTML代码的情况下,在第一次点击后多次调用函数动画?我需要保留代码中的 id 和 class。我试图将 display 属性设置为 none,但它似乎不起作用。我希望动画在单击<p> 标签时开始,但是一旦我第一次单击它,动画就不会再次开始。即使在动画中间,我也想再次调用该函数。我阅读了有关该主题的所有其他问题,但它们似乎对我不起作用,因为 HTML 不同。请不要使用Jquery,但可以使用普通的JS。谢谢!
<!DOCTYPE html>
<html>
<head>
<style>
.something {
background:blue;
height:20px;
width:20px;}
.earth{
position :relative;
animation:move 10s linear;
background:red;
height:20px;
width:20px;
}
@-webkit-keyframes move
{
from { left: 0%; }
to { left: 100%; }
}
</style>
<script>
function changetext (){
document.getElementById("demo").style.color = "red";
animation();
}
function animation(){
document.getElementById('ghost').className ='earth';
}
function repeat(){
var sd = document.getElementById("ghost").className ='earth';
sd.style.display = 'none';
}
</script>
</head>
<body>
<div class="something"></div>
<div id="ghost"> </div>
<p onclick="changetext();" id="demo"> HELLO WORLD </p>
</body>
</html>
【问题讨论】:
标签: javascript css