登录  /  注册
首页 > web前端 > css教程 > 正文

怎样用CSS3和JS做出上升的方块动态背景

php中世界最好的语言
发布: 2017-11-25 15:34:19
原创
2149人浏览过

我们知道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(&#39;F-dynamicbg-box&#39;), div = box.getElementsByTagName(&#39;div&#39;), 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] + &#39;px&#39;; div[i].style.height = math[1] + &#39;px&#39;; math[2] = math[1]; } } for(var i=0;i<div.length;i++){ div[i].style.left = F_getSJS(85,15,8) + &#39;vw&#39;; div[i].style.transform = &#39;rotate(&#39; + F_getSJS(360,5,9) + &#39;deg)&#39;; }
登录后复制

所有的代码都在这里了,感兴趣的朋友可以自己动手操作一下,,更多精彩请关注php中文网其它相关文章!

相关阅读:

HTML里的最后一行文字显示不全怎么处理

CSS网页错位怎么处理

CSS3的loading特效怎么制作

以上就是怎样用CSS3和JS做出上升的方块动态背景的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
css
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号