本文实例讲述了js实现的页面矩阵图形变换特效。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>matrix</title> <style type="text/css"> body { margin:0; padding:0;background:black; } .rect { background:green; } .arc { border-radius:5px; background:green; box-shadow:2px solid #fff; } ul { list-style:none; margin:0; padding:0; position:absolute; } li { width:20px; height:20px; position:absolute; } h1 { text-align:center; line-height:150px; font-size:150px; color:green; } </style> </head> <body> <h1>Chrome下兼容</h1> </body> <script type="text/javascript"> var body = document.getElementsByTagName("body")[0]; function getColor() { var color = "rgb("; color += (10+Math.round(Math.random()*245)); color += ","; color += (10+Math.round(Math.random()*245)); color += ","; color += (10+Math.round(Math.random()*245)); color += ")"; return color; } var matrixData = [ [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1] ]; var matrixData2 = [ [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0],//1 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],//2 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],//3 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],//4 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],//5 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],//6 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],//7 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0],//8 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],//9 [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],//9 [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],//10 [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],//11 [0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],//12 [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0] //13 ]; function createDom(attrs) { var dom = document.createElement(attrs.tagName); attrs.style "style", attrs.style) : void(0); attrs.on "data-on", attrs.on) : void(0); return dom; } var ulList = []; var width = window.innerWidth; var height = window.innerHeight; var cols = Math.floor(width/120); var rows = Math.floor(height/120); var xOffset = Math.floor((width%120)/2); function createFlyer(attrs) { var iLength = matrixData.length, jLength = matrixData[0].length, radius = 20, ul = null, bgColor = getColor(); ul = createDom({tagName: "ul", style: "height:"+iLength*radius+"px; width:"+jLength*radius+"px; left:"+attrs.left+"px; top:"+attrs.top+"px"}); document.body.appendChild(ul); for(var i=0; i<5; i++) { var _data = matrixData[i]; for(var j=0; j<5; j++) { var style = "width:"+radius+"px; height:"+radius+"px;left:"+j*radius+"px; top:"+i*radius+"px;background:"+(_data[j] == 0 "transparent": bgColor); var li = createDom({tagName: "li", style: style, on: _data[j] "li"); for(var i=0,length=lis.length; i<length; i++) { var _li = lis[i]; console.log(_li.getAttribute("data-on")); _li.getAttribute("data-on") "rotate("+angle+"deg)"; } }, 50); } function createMatrix2() { body.innerHTML = ""; var iLength = matrixData2.length, jLength = matrixData2[0].length, radius = 20, ul = null, height = jLength*radius, width = iLength*radius, bgColor = getColor(), left = (window.innerWidth - width)/2, top = (window.innerHeight - height)/2 console.log(window.innerWidth); console.log(width); ul = createDom({tagName: "ul", style: "height:"+iLength*radius+"px; width:"+jLength*radius+"px; left:"+left+"px; top:"+top+"px"}); document.body.appendChild(ul); for(var i=0; i<iLength; i++) { var _data = matrixData2[i]; for(var j=0; j<jLength; j++) { var style = "width:"+radius+"px; height:"+radius+"px;left:"+j*radius+"px; top:"+i*radius+"px;background:"+(_data[j] == 0 "transparent": getColor()); var li = createDom({tagName: "li", style: style, on: _data[j] "arc"; ul.appendChild(li); } } ul.style.webkitTransform = "scale(0.1, 0.1)"; var scale = 0.1; var interval = setInterval(function() { ul.style.webkitTransform = "scale("+scale+", "+scale+")"; scale += 0.1; if(scale > 1) { clearInterval(interval); } }, 50); } firstStep(); </script> </html>
更多关于js特效相关内容感兴趣的读者可查看本站专题:《jQuery动画与特效用法总结》及《jQuery常见经典特效汇总》
希望本文所述对大家JavaScript程序设计有所帮助。
标签:
js,页面矩阵,图形变换,特效
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“js实现的页面矩阵图形变换特效”评论...
更新动态
2024年11月13日
2024年11月13日
- 《英雄联盟》Doinb想让Tian当教练:世纪大和解?
- 《忆蚀》Subliminal:揭秘后室之谜,路知行献声Weplay文化展
- 那英《征服NEWXRCD台湾版》日本压制[WAV+CUE]
- 群星《金曲百分百上》3CD(香港版)[WAV+CUE]
- 刘欢《雨中的树(新歌加精选)2CD》德国HD24K金碟[WAV+CUE]
- 郑源 《世间情歌》6N纯银SQCD[WAV+CUE][1G]
- 群星《粤潮2HQII》头版限量编号[低速原抓WAV+CUE][991M]
- 群星《2023好听新歌21》十倍音质 U盘音乐[WAV分轨][1G]
- 《热血传奇》双11感恩回馈 超值狂欢30天
- 原神5.2版本活动汇总 5.2版本活动有哪些
- 张敬轩.2010-NO.ELEVEN【环球】【WAV+CUE】
- 黄丽玲.2006-失恋无罪【艾回】【WAV+CUE】
- 阿达娃.2024-Laluna【W8VES】【FLAC分轨】
- 宝可梦大集结段位等级划分表大全 大集结段位一览
- 龙腾世纪影障守护者工坊与装备如何升级 工坊与装备升级说明