DDR爱好者之家 Design By 杰米
本文实例讲述了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程序设计有所帮助。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]