在html5页面中用js怎么实现这些效果,新手求解
发布网友
发布时间:2022-04-22 07:42
我来回答
共2个回答
热心网友
时间:2022-06-17 22:46
给你做 第一个,用的是css3和js实现的。
下面的3个都可以用js实现,如果要做的好看一点的话,可以用jquery或者其他的组件
<!DOCTYPE html>
<html>
<head>
<style>
.move
{
width:100px;
height:100px;
background:red;
position:relative;
animation-name:myfirst;
animation-ration:5s;
animation-timing-function:linear;
animation-delay:0;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:paused;
/* Firefox: */
-moz-animation-name:myfirst;
-moz-animation-ration:5s;
-moz-animation-timing-function:linear;
-moz-animation-delay:0;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:alternate;
-moz-animation-play-state:paused;
/* Safari and Chrome: */
-webkit-animation-name:myfirst;
-webkit-animation-ration:5s;
-webkit-animation-timing-function:linear;
-webkit-animation-delay:0;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:paused;
/* Opera: */
-o-animation-name:myfirst;
-o-animation-ration:5s;
-o-animation-timing-function:linear;
-o-animation-delay:0;
-o-animation-iteration-count:infinite;
-o-animation-direction:alternate;
-o-animation-play-state:paused;
}
@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;}
}
@-moz-keyframes myfirst /* Firefox */
{
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;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */
{
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;}
}
@-o-keyframes myfirst /* Opera */
{
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;}
}
.c{
position: absolute;
width:300px;
height: 300px;
border:solid 1px red;
}
</style>
</head>
<body>
<p><b>注释:</b>本例在 Internet Explorer 中无效。</p>
<div class="c">
<div class="move" id="move"></div>
</div>
</body>
<script>
window.onload = function(){
document.getElementById("move").onclick = function(){
this.style.animationPlayState = "running";
}
}
</script>
</html>
热心网友
时间:2022-06-17 22:47
JavaScript可以追问可以帮我写吗