html定义运动的代码
导读:HTML定义运动的代码:<!DOCTYPE html><html><head><title>运动效果</title><style>.box {width: 100px;...
HTML定义运动的代码:
!DOCTYPE html>
html>
head>
title>
运动效果/title>
style>
.box {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
left: 0;
top: 0;
animation: move 2s ease-in-out infinite alternate;
}
@keyframes move {
from {
left: 0;
top: 0;
}
to {
left: 200px;
top: 200px;
}
}
/style>
/head>
body>
div class="box">
/div>
/body>
/html>
以上是HTML定义运动的代码。其中,通过 CSS 的 animation 属性实现了一个平移的效果,这个效果在 2 秒内完成,采用了 ease-in-out 算法,并且在结束前进行反向播放,所以整个动画效果是无限循环的。观察代码可以发现, keyframes 是用来定义动画的关键帧,from 内容将会在动画开始时生效,to 内容将会在动画结束时生效。在本例中,运动元素通过改变左侧和顶部的值,实现了向右下方运动的效果。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: html定义运动的代码
本文地址: https://pptw.com/jishu/306164.html
