用碎片加载小方块实现简单的随机色块,直接上代码:
效果图:
具体代码:
<!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程序设计有所帮助。
标签:
javascript,加载
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“javascript实现简单加载随机色方块”评论...
更新动态
2024年11月15日
2024年11月15日
- 谭咏麟《20世纪中华歌坛名人百集珍藏版》[WAV+CUE][1G]
- 炉石传说40轮盘术最新卡组代码在哪找 标准40轮盘术卡组代码分享
- 炉石传说亲王贼怎么玩 2024亲王贼最新卡组代码分享
- 炉石传说30.6.2补丁后有什么卡组 30.6.2最强卡组最新推荐
- 模拟之声慢刻CD《蔡琴名曲回顾遇听》[原抓WAV+CUE]
- BruceLiu-WAVES(MusicbySatie)(2024)2CD[24Bit-96kHz]FLAC
- KonstantinKrimmel-MythosSchubertLoewe(2024)[24Bit-96kHz]FLAC
- 2024雷蛇高校挑战赛 嘤式分解助力收官之战
- 海信发布110吋世俱杯官方定制AI电视 引领智能观赛
- 海信发布27英寸显示器大圣G5 Pro:采用自研超解析芯片、友达原厂模组
- 蔡琴《机遇》1:1母盘直刻日本头版[WAV分轨][1.1G]
- 陈百强《与你几分钟的约会》XRCD+SHMCD限量编号版[低速原抓WAV+CUE][994M]
- 陈洁丽《监听王NO.1 》示范级发烧天碟[WAV+分轨][1.1G]
- 单色凌.2014-小岁月太着急【海蝶】【WAV+CUE】
- 陈淑桦.1988-抱紧我HOLD.ME.NOW【EMI百代】【WAV+CUE】