圆周运动的css3特效案例

<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>圆周运动的css3特效</title>
<style>
.box{
width:300px;
height:300px;
margin:200px auto;
position:relative;
-webkit-perspective:1500px;
}
.div{
width:300px;
height:300px;
position:absolute;
transform-style:preserve-3d;
animation:name 8s linear infinite;
transform:rotateX(0deg) rotateY(0deg);
}
@-webkit-keyframes name {
from{
transform:rotateX(0deg) rotateY(0deg);
}
to{
transform:rotateX(360deg) rotateY(360deg);
}
}
.div>div{
width:300px;
height:300px;
border:black 1px solid;
position:absolute;
border-radius:50%;
}
.box1{
transform:rotateY(0deg);
}
.box2{
transform:rotateY(120deg);
}
.box3{
transform:rotateY(240deg);
}
.inner{
width:6px;
height:6px;
position:absolute;
top:300px;
left:150px;
}
</style>
</head>
<body>
<div class="box">
<div class="div">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</div>
</div>
</body>
</html>
<script>
var box1=document.querySelector(".box1");
var box2=document.querySelector(".box2");
var box3=document.querySelector(".box3");
function create(a){
for(var i=0;i<100;i++){
var div=document.createElement("div");
div.className="inner";
a.appendChild(div)
}
}
create(box1)
create(box2)
create(box3)
function an(b){
var inner=b.querySelectorAll(".inner");
var i=0; //角度
var j=0; //元素下标
var pi=Math.PI/180;
var t=null;
t=setInterval(function(){
i++;
if(i>=360){
i=0;
}
if(j>=100){
j=0;
}
inner[j].style.background="rgb("+Math.floor(Math.random()*225)+","+Math.floor(Math.random()*225)+","+Math.floor(Math.random()*225)+")";
inner[j].style.left=150+Math.floor(150*Math.sin(i*pi))-3+"px";
inner[j].style.top=150-Math.floor(150*Math.cos(i*pi))-3+"px";
j++;
},10)
}
an(box1);
an(box2);
an(box3);
</script>

转载于:https://www.cnblogs.com/shangjun6/p/10819742.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值