时间:2021-05-26
用碎片加载小方块实现简单的随机色块,直接上代码:
效果图:
具体代码:
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); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); 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); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); 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); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); 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); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } 50% { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); -webkit-transition: opacity 1s linear; transition: opacity 1s linear; opacity: .5; filter: alpha(opacity=50); } 100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); 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); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg); -webkit-transition: opacity .3s linear; transition: opacity .3s linear; opacity: .5; filter: alpha(opacity=50); } 50% { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); -webkit-transition: opacity 1s linear; transition: opacity 1s linear; opacity: .5; filter: alpha(opacity=50); } 100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); 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程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了javascript文件加载管理简单实现方法。分享给大家供大家参考。具体如下:这里介绍超级简单的进行javascript的文件(模块)的加载管理,
js简单实现点名器随机色布局(排版)开始结束css样式#box{width:240px;height:400px;}#a{width:80px;height:4
下面一段代码就是用js实现的随机颜色的小方块,不多说了代码很简单,直接上代码了。js注释已删koringz*{-webkit-box-sizing:bo
本文实例讲述了原生javaScript实现图片延时加载的方法。图片延时加载其实是有jquery插件了并且加载方法非常的简单并且合理了,但有朋友觉得加载jquer
本文实例为大家分享了javascript实现点击产生随机图形的具体代码,供大家参考,具体内容如下点击产生随机图形效果如下:用javascript来实现主要用ca