js css3写嵌套立方体动画效果(大立方内套小立方)
来源:互联网 发布:java序列化如何实现 编辑:程序博客网 时间:2024/05/22 00:23
先上图:
HTML:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="style.css"></head><body><div class="container"></div><script src="app.js"></script></body></html>
CSS:
body{ background-color: black;}@keyframes rotate { from{ transform: rotateX(0deg) rotateY(0deg); } to{ transform: rotateX(360deg) rotateY(360deg); }}
JS:
/** * Created by Administrator on 2017/8/15. */(function () { //同步创建两套子元素,根据传入的className名设置立方大小和样式 function cube(className,maxWidth) { var width = className==="out-cube"?maxWidth:maxWidth/2; var bg = document.createElement("div"); bg.style.cssText = "width: "+width+"px;height: "+width+"px;position: absolute;"; var ul = document.createElement("ul"); bg.appendChild(ul); ul.style.cssText = "width: "+width+"px;height: "+width+"px;list-style: none;position: relative;transform-style: preserve-3d;"; ul.setAttribute("class",className); var styles = ["background-color: #0970ff;transform: translateZ("+width/2+"px);","background-color: #bb5eff;transform: translateZ("+-width/2+"px);","background-color: #b9ffae;transform: rotateY(-90deg) translateZ("+width/2+"px);","background-color: #ffdf38;transform: rotateY(90deg) translateZ("+width/2+"px);","background-color: #61ff4d;transform: rotateX(-90deg) translateZ("+width/2+"px);","background-color: #ff328a;transform: rotateX(90deg) translateZ("+width/2+"px);"]; for (var i=0;i<styles.length;i++){ var li = document.createElement("li"); var css = styles[i]+"opacity: 0.4;width: "+width+"px;height: "+width+"px;position: absolute;"; css+=className==="in-cube"?"left: 50%;top: 50%;":""; li.style.cssText = css; ul.appendChild(li); } return bg; } //封装创建立方体元素的函数 function doubleCub(width) { var container = document.createElement("div"); //设置父元素样式调用rotate方法 container.style.cssText = "width: "+width+"px;height: "+width+"px;margin: 200px auto;transform-style: preserve-3d;animation: rotate 5s linear 0s infinite;"; //调用cube函数同步创建两套子元素 //大立方 container.appendChild(cube("out-cube",width)); //小立方 container.appendChild(cube("in-cube",width)); return container; } //封装init函数将元素放到body里并传参设置立方体大小 function init() { document.body.appendChild(doubleCub(200)); } init();})();
阅读全文
0 0
- js css3写嵌套立方体动画效果(大立方内套小立方)
- js 立方 平方怎么写
- 运用three.js写的漂浮立方
- 纯css3写的立方体动画
- 【湘大oj】1173-(立方和)
- CSS3嵌套立方体旋转
- 立方数(枚举)
- 习题6.4(立方)
- 【NOJ】(Java)完美立方
- 枚举(例题:完美立方)
- 立方差数(枚举+数学)
- 人立方
- 完美立方
- 数据立方
- 完美立方
- 立方跟
- 完美立方
- 完美立方
- idea中显示svn修改人,修改时间
- Java注解的工作原理
- 第2章_线性表
- QT 自带的数据库 QSQLITE
- Htttp.AddHeader()参数、页面的缓存与不缓存设置
- js css3写嵌套立方体动画效果(大立方内套小立方)
- 06_笨小猴
- makefile 经典教程
- redis集群搭建
- arcgis图层的分类
- 下载Tomcat时core和deployer的区别
- FreeMarker入门一
- 跨浏览器的事件处理程序
- java操作(DOM、SAX、JDOM、DOM4J)xml方式的四种比较与详解