我们知道css3是可以做出很多酷炫的动画的,那么如果css3和js结合起来使用那该有多么强大呢?今天教大家怎样用css和js制作出上升的方块的动态背景,一起来看一下。
html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>glunefish</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="f-dynamicbg-box">
<div> </div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
css:
* { margin: 0; padding: 0; border: none; outline: 0; }
body{ width: 100vw; height: 100vh; background: url(img/bg.png) no-repeat; background-size: cover; }
#f-dynamicbg-box { width: 100vw; height: 100vh; position: absolute; top: 0; left: 0; overflow: hidden; }
#f-dynamicbg-box > div { z-index: -9999; background-color: rgba(255,255,255,.1); position: absolute; top: 105vh; animation: dynamicdiv 30s linear infinite; }
#f-dynamicbg-box > div:nth-of-type(1) { animation-delay: 1s }
#f-dynamicbg-box > div:nth-of-type(2) { animation-delay: 3s }
#f-dynamicbg-box > div:nth-of-type(3) { animation-delay: 6s }
#f-dynamicbg-box > div:nth-of-type(4) { animation-delay: 9s }
#f-dynamicbg-box > div:nth-of-type(5) { animation-delay: 12s }
#f-dynamicbg-box > div:nth-of-type(6) { animation-delay: 4s }
#f-dynamicbg-box > div:nth-of-type(7) { animation-delay: 15s }
#f-dynamicbg-box > div:nth-of-type(8) { animation-delay: 18s }
#f-dynamicbg-box > div:nth-of-type(9) { animation-delay: 20s }
#f-dynamicbg-box > div:nth-of-type(10) { animation-delay: 16s }
@keyframes dynamicdiv { form { top: 105vh; transform: scale(1.2); }
to { top: -13vh; transform: scale(1) rotate(60deg); } }
js:( js初始化div形态 )
var box = document.getelementbyid('f-dynamicbg-box'), div = box.getelementsbytagname('div'), math = [0,1];for (var i=0;i<div.length;i++) { math[1] = f_getsjs(100,40,9) f_getsjs 请移步博客之前的取随机数了解if(math[1] != math[2]){ div[i].style.width = math[1] + 'px'; div[i].style.height = math[1] + 'px'; math[2] = math[1]; } } for(var i=0;i<div.length;i++){ div[i].style.left = f_getsjs(85,15,8) + 'vw'; div[i].style.transform = 'rotate(' + f_getsjs(360,5,9) + 'deg)'; }
所有的代码都在这里了,感兴趣的朋友可以自己动手操作一下,,更多精彩请关注其它相关文章!
相关阅读:
html里的最后一行文字显示不全怎么处理
css网页错位怎么处理
css3的loading特效怎么制作
以上就是怎样用css3和js做出上升的方块动态背景的详细内容。