javascript实现简单加载随机色方块
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要介绍了javascript实现简单加载随机色方块的相关资料,感兴趣的小伙伴们可以参考一下
用碎片加载小方块实现简单的随机色块,直接上代码
效果图
具体代码
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <title>koringz</title> <link rel="stylesheet" href="css/demo.css"> </head> <body> <div class="container"> <div class="main"> <div class="colorful"></div> </div> </div> </body> </html>
css代码
{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } html { font-size: 10px; -webkit-tap-highlight-color: transparent; } body { margin: 0; padding: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.42857143; color: #333; background-color: rgba(211,232,132,0.8); } .container { overflow: visible; } .main { position: relative; width: 90%; height:200px; margin:auto; } .colorful { overflow: visible; width: 100%; height: 100%; } .colorful > a { float: left; display: block; width: 50px; height: 50px; zoom:2; } .colorful > a:hover { -webkit-animation:infinite 2s ease-in-out start-roll; -moz-animation:infinite 2s ease-in-out start-roll; animation:infinite 2s ease-in-out start-roll; } @-webkit-keyframes start-roll{ 0% { -webkit-transform: rotate(0deg); /chrome/ -moz-transform: rotate(0deg); /火狐/ -ms-transform: rotate(0deg); /IE/ transform: rotate(0deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); zoom:1; } 50% { -webkit-transform: rotate(180deg); /chrome/ -moz-transform: rotate(180deg); /火狐/ -ms-transform: rotate(180deg); /IE/ transform: rotate(180deg); -webkit-transition: opacity 1s linear; transition: opacity 1s linear; opacity: 1; filter: alpha(opacity=100); zoom:2; } 100% { -webkit-transform: rotate(360deg); /chrome/ -moz-transform: rotate(360deg); /火狐/ -ms-transform: rotate(360deg); /IE/ transform: rotate(360deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); zoom:1; } } @-moz-keyframes start-roll{ 0% { -webkit-transform: rotate(0deg); /chrome/ -moz-transform: rotate(0deg); /火狐/ -ms-transform: rotate(0deg); /IE/ transform: rotate(0deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } 50% { -webkit-transform: rotate(180deg); /chrome/ -moz-transform: rotate(180deg); /火狐/ -ms-transform: rotate(180deg); /IE/ transform: rotate(180deg); -webkit-transition: opacity 1s linear; transition: opacity 1s linear; opacity: .5; filter: alpha(opacity=50); } 100% { -webkit-transform: rotate(360deg); /chrome/ -moz-transform: rotate(360deg); /火狐/ -ms-transform: rotate(360deg); /IE/ transform: rotate(360deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } } @keyframes start-roll{ 0% { -webkit-transform: rotate(0deg); /chrome/ -moz-transform: rotate(0deg); /火狐/ -ms-transform: rotate(0deg); /IE/ transform: rotate(0deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } 50% { -webkit-transform: rotate(180deg); /chrome/ -moz-transform: rotate(180deg); /火狐/ -ms-transform: rotate(180deg); /IE/ transform: rotate(180deg); -webkit-transition: opacity 1s linear; transition: opacity 1s linear; opacity: .5; filter: alpha(opacity=50); } 100% { -webkit-transform: rotate(360deg); /chrome/ -moz-transform: rotate(360deg); /火狐/ -ms-transform: rotate(360deg); /IE/ transform: rotate(360deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } }
js代码
(function (window) { var document = window.document; function on(elem, evtnm, eventhd) { var onevtnm = 'on' + evtnm; elem[onevtnm] = eventhd; } function grc() { var val = [], i = 0; while (++i <= 3) { val.push(Math.floor(Math.random() 255)); } return 'rgb(' + val.join() + ')'; } function fbc() { var el = document.querySelectorAll('.colorful')[0], total = Math.floor(el.offsetWidth / 50) Math.floor(el.offsetHeight / 50), df = document.createDocumentFragment(), a; while (total-- > 0) { a = document.createElement('a'); a.style.backgroundColor = grc(); df.appendChild(a); } el.appendChild(df); } on(window, 'load', function () { fbc(); }); })(window)
希望本文所述对大家学习javascript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程