html5 css3做圆周运动,圆周运动的css3特效案例

本文介绍了一种使用CSS3实现的圆周运动特效,并通过JavaScript动态改变元素颜色及位置来模拟圆周运动效果,适用于网页动画制作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

圆周运动的css3特效

.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;

}

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);

原文:https://www.cnblogs.com/shangjun6/p/10819742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值