<!DOCTYPE html>
<html>
<head>
<style>
.my-animation
{
width:100px;
height:100px;
background:red;
position:relative;
animation-name:myfirst;
animation-duration:5s;
animation-timing-function:linear;
animation-delay:2s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
animation:myfirst 5s linear 2s infinite alternate;
}
@keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
.my-transition
{
margin-top: 200px;
width:100px;
height:100px;
background:yellow;
transition:width 2s linear 1s, height 2s linear 1s, transform 2s linear 1s;
}
.my-transition:hover
{
width:200px;
height:200px;
transform:rotate(180deg);
}
.my-click-transiton
{
width:250px;
height:250px;
transform:rotate(270deg);
}
</style>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
</head>
<body>
<div class="my-animation"></div>
<div class="my-transition">请把鼠标指针放到黄色的 div 元素上,来查看过渡效果。</div>
<input type="button" id="mybutton" value="click">
<script>
$('#mybutton').click(function () {
var myTransition = $('.my-transition');
if (myTransition.hasClass('my-click-transiton')) {
myTransition.removeClass('my-click-transiton')
} else {
$('.my-transition').addClass('my-click-transiton');
}
});
</script>
</body>
</html>

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步