gpt4 book ai didi

javascript - CSS3 关键帧不工作

转载 作者:行者123 更新时间:2023-11-28 08:50:50 24 4
gpt4 key购买 nike

下面是代码-

.startanimation {
height: 100px;
width: 100px;
background: yellow;
-webkit-animation: animate 1s infinite;
}

@-webkit-keyframes animate {
100% {
width: 300px;
height: 300px;
}
}

在 HTML 中,当一个元素被赋予一个类“startanimation”时,动画就会起作用。但是当使用“addClass”方法将同一个类添加到另一个元素时,该动画不起作用。有什么想法吗?

最佳答案

演示 - http://jsfiddle.net/d3md7597/1/

$('#start').on('click', function() {
$('#x').addClass('startanimation')
})
$('#stop').on('click', function() {
$('#x').removeClass('startanimation')
})
#x {
background: pink;
height: 100px;
width: 100px;
border-radius: 50%;
position: absolute;
left: 300px;
top: 200px;
}
.startanimation {
height: 100px;
width: 100px;
background: yellow;
-webkit-animation: animate 1s infinite;
}
@-webkit-keyframes animate {
100% {
width: 300px;
height: 300px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button id="start">Start</button>
<button id="stop">Stop</button>
<br>
<br>
<div id="x"></div>

关于javascript - CSS3 关键帧不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27354606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com