css实现圆环旋转加载
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css实现圆环旋转加载</title>
<style>
*{
margin:0
padding:0
}
#outbox{
position:relative/*相对定位*/
width:100px/*宽度100px*/
height:100px/*高度100px*/
background:orange/*背景色橙色*/
border-radius:50%/*圆角50%*/
margin:100px/*外侧边距100px*/
}
#outbox::before{/*前置伪元素*/
content:""/*内容空*/
display:block/*块元素*/
position:absolute/*绝对定位*/
width:80px/*宽度80px*/
height:80px/*高度80px*/
left:10px/*左边距10px*/
top:10px/*距离顶部10px*/
border-radius:50%/*圆角50%*/
background:white/*背景色白色*/
}
#outbox::after{/*后置伪元素*/
content:""/*内容为空*/
display:block/*转为块元素*/
position:absolute/*绝对定位*/
width:100px/*宽度100px*/
height:100px/*高度100px*/
top:0/*距离父容器顶部边距0*/
left:0/*距离入容器左边距0*/
border-radius:50%/*圆角50%*/
background:white/*背景色白色*/
animation:myfirst 1s both linear infinite/*绑定动画。为了看清楚效果,设置动画反复执行。使用的时候只执行一次就好了*/
-webkit-animation:myfirst 1s both linear infinite/* Safari and Chrome */
}
@keyframes myfirst/*动画开始*/
{
0%{
-webkit-clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 0, 100% 0)/*不裁剪的初始效果*/
clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 0, 100% 0)
}
40%{
-webkit-clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 0, 0 0)/*裁剪四分之一*/
clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 0, 0 0)
}
60%{
-webkit-clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 100%, 0 100%)/*裁剪四分之二*/
clip-path: polygon(50% 50%, 100% 0, 100% 100%, 0 100%, 0 100%, 0 100%)
}
90%{
-webkit-clip-path: polygon(50% 50%, 100% 0, 100% 100%, 100% 100%, 100% 100%, 100% 100%)/*裁剪四分之三*/
clip-path: polygon(50% 50%, 100% 0, 100% 100%, 100% 100%, 100% 100%, 100% 100%)
}
100%{
-webkit-clip-path: polygon(50% 50%, 100% 0, 100% 100%, 100% 0, 100% 0, 100% 0)/*裁剪四分之四*/
clip-path: polygon(50% 50%, 100% 0, 100% 100%, 100% 0, 100% 0, 100% 0)
}
}
</style>
</head>
<body>
<div id="outbox"></div>
</body>
</html>
<!--裁剪比较粗糙,如果要更顺滑,可以裁剪得更细腻一点,比如裁剪十分之一,十分之二,十分之三,以此类推一直到十分之十。-->
1、首先新建一个html空白文档,取名字叫做css3动画,保存一下。
2、然后写html结构,只需要一个div元素即可,class名字叫做img
3、设置其边框为不同的颜色,边框宽度设置成100px。
4、因为是圆环,所以我们用到了css3的圆角效果,设置圆角为50%,也就是border-radius:50%,看一下效果。
5、接下来就是关键的步骤了,也就是添加动画效果。输入以下代码
6、来看一下最后的效果,还是不错的。
不知道这合不合你意,,不过你这个要求,,可以搜索一下一些JQUERY效果,, <html><head>
<title>图片环形滚动</title>
<style>
html,body{background:#990000margin:0px }
#pics_3d{
position:absolute
height:300px
width:100%
background:#000
top:120px
border-bottom:20px solid #420000
border-top:20px solid #420000
}
img{
position:absolute
background:#eee
left:0top:0
border:5px solid #00CCFF
}
</style>
</head>
<body>
<div id="pics_3d">
<img src="/jscss/demoimg/wall5.jpg" />
<img src="/jscss/demoimg/wall6.jpg" />
<img src="/jscss/demoimg/wall7.jpg" />
</div>
</body>
<script >
Item=function(UI){
this.angle=0
this.UI=UI
this.update()
}
Item.ini={
axle_w:400,
axle_h:10,
cen_x:500,
cen_y:260
}
Item.prototype.update=function(){
var J=this.UI.style,C=Item.ini,W=C.axle_w,H=C.axle_h,X=C.cen_x,Y=C.cen_y
var angle=this.angle/180*Math.PI
var left=Math.cos(angle)*W+X
var top=Math.sin(angle)*H+Y
var A=this.angle>270?this.angle-360:this.angle
var size=360-Math.abs(90-A)*3
this.UI.width=Math.max(size,120)
var opacity=Math.max(10,size-180)
J.filter='alpha(opacity='+opacity+')'
J.opacity=opacity/100
J.left=(left-this.UI.offsetWidth/2)+'px'
top=(top-this.UI.offsetHeight)+'px'
J.top=top
J.zIndex=parseInt(size*100)
}
Nav_3D={
items:[],
dir:1,
index:0,
hover:false,
add:function(item){
this.items.push(item)
item.index=this.items.length-1
item.UI.onclick=function (){
var J=item.angle,M=Nav_3D
if(M.uping)return
if(J==90){
return alert('goto new url..')
}
M.wheel_90(item)
M.index=item.index
}
item.UI.onmouseover=function (){
if(item.angle==90){
Nav_3D.hover=true
clearTimeout(Nav_3D.autoTimer)
}
}
item.UI.onmouseout=function (){
if(item.angle==90){
Nav_3D.hover=false
Nav_3D.auto()
}
}
return this
},
wheel_90:function(hot){
if(this.uping)return
this.uping=true
var This=this
this.timer=setInterval(function (){
clearTimeout(This.autoTimer)
var A=hot.angle
This.dir=A<270&&A>90?-1:1
if(A==90){
clearInterval(This.timer)
This.uping=false
This.onEnd(hot)
}
if(A>270)A-=360
var set=Math.ceil(Math.abs((90-A)*0.1))
for (var i=0i<This.items.lengthi++ ) {
var J=This.items[i]
J.angle+= (set*This.dir)
J.update()
if(J.angle>360)J.angle-=360
if(J.angle<0)J.angle +=360
}
},15)
},
ready:function(){
var J=this.items,step=parseInt(360/J.length)
for (var i=0i<J.lengthi++) {J[i].angle=i*step+90}
this.wheel_90(this.items[0])
Nav_3D.prevHot=this.items[0].UI
Nav_3D.setHot()
},
setHot:function(isHot){
if(!this.prevHot)return
with(this.prevHot.style){
borderColor=isHot!==false?'#CC0000':'#00CCFF'
cursor=isHot!==false?'default':"pointer"
}
return this
},
auto:function(){
this.index--
if(this.index<0)this.index=this.items.length-1
var J=this.items[this.index]
this.setHot(false).prevHot=J.UI
this.setHot()
this.wheel_90(J)
},
onEnd:function(hot){
if(this.hover){
return setTimeout(function(){Nav_3D.onEnd()},100)
}
this.autoTimer=setTimeout(function(){Nav_3D.auto()},1500)
}
}
var imgs=document.getElementById("pics_3d").getElementsByTagName("IMG")
for (var i=0i<imgs.lengthi++ ) {
Nav_3D.add(new Item(imgs[i]))
}
Nav_3D.ready()
</script>
</html>