关于利用css动画制作骰子运动
2017-03-27 17:47
393 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> body,li,ul{ margin:0; padding: 0; } li{ list-style: none; } .dice{ position: relative; width: 125px; height: 125px; margin: 50px auto 0; transform-style:preserve-3d;/*关键属性*/ /* -webkit-perspective: 125;透视*/ /*transform: rotate3d(1,1,1,45deg);*/ transition:transform 2s; } .dice li{ position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; text-indent: -99em; background:url("images/bg.jpg") no-repeat;} .dice li:nth-child(1){ background-position:-263px -259px; transform:translateZ(62.5px);} .dice li:nth-child(2){ background-position:-10px -132px; transform:rotateY(90deg) translateZ(-62.5px);} .dice li:nth-child(3){ background-position:-137px -131px; transform:rotateY(90deg) rotateX(90deg) translateZ(-62.5px);} .dice li:nth-child(4){ background-position:-263px -132px; transform:rotateY(90deg) translateZ(62.5px);} .dice li:nth-child(5){ background-position:-391px -132px; transform:rotateY(90deg) rotateX(90deg) translateZ(62.5px);} .dice li:nth-child(6){ background-position:-264px -5px; transform:translateZ(-62.5px);} .btn{ position: relative; margin-top:150px; } .btn input{ position: absolute; left: 50%; top: 0; } .btn input:nth-child(1){margin-left:-50px;} .btn input:nth-child(2){margin-left:50px;} .btn input:nth-child(3){margin-top:-50px;} .btn input:nth-child(4){margin-top:50px;} .btn input:nth-child(5){ margin-left:-10px;} @keyframes doDo{ 0%{transform: rotate3d(1,1,1,0);} 100%{ transform: rotate3d(1,1,1,360deg); } } .autoDo{ animation: doDo 5s linear infinite; } </style> </head> <body> <ul class="dice"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> <div class="btn"> <input class="left" type="button" value="左" /> <input class="right" type="button" value="右" /> <input class="top" type="button" value="上" /> <input class="bottom" type="button" value="下" /> <input class="forever" type="button" value="自动转" /> </div> <script src="http://cdn.cdnjs.net/jquery/1.11.1/jquery.min.js"></script> <script> var rotateObj={ ulNode:$('.dice'), btnNode:$('.btn'), inputNodes:$('.btn input'), y:0, x:0, clickFun:function(e){//上右下左旋转的点击函数 var _this=this; var target=e.target; if($(target).hasClass('forever')) return; if(_this.ulNode.css('animation-play-state')=='running'){ _this.ulNode.removeClass('autoDo'); } if($(target).hasClass('left')){//左 _this.y-=90; } else if($(target).hasClass('right'))//右 { _this.y+=90; } else if($(target).hasClass('top'))//上 { _this.x+=90; } else if($(target).hasClass('bottom'))//下 { _this.x-=90; } window.setTimeout(function(){ _this.ulNode.css('transform',"rotateY("+_this.y+"deg) rotateX("+_this.x+"deg)"); },0); }, autoRotateFun:function(e){ var _this=this; var target=e.target; if(!$(target).hasClass('forever')) return; _this.ulNode.addClass('autoDo'); }, init:function(){ var _this=this; _this.btnNode.click(function(e){ _this.clickFun(e); }); _this.btnNode.click(function(e){ _this.autoRotateFun(e); }); } }; rotateObj.init(); </script> </body> </html>
相关文章推荐
- 使用HTML语言和CSS开发商业站点_利用CSS3制作网页动画
- 利用CSS制作菜单 教程
- Visual C# 2005 - 利用程序代码制作简单动画效果
- 利用DIV+CSS制作浮动广告,没有用到多少javascript,全是css
- 如何利用地图API制作汽车沿道路行驶的动画?——如何获得道路层数据
- 【百度地图API】如何利用地图API制作汽车沿道路行驶的动画?——如何获得道路层数据
- 关于利用css定制下拉菜单
- 在3ds max中,利用normal map 制作精美骰子
- 【百度地图API】如何利用地图API制作汽车沿道路行驶的动画?——如何获得道路层数据
- 利用VML标记语言画图、动画制作
- 原创:利用JS制作GIF动画图(及图片轮转显示效果)
- Web标准化制作:利用CSS按比例缩小图片
- VC中利用FLASH制作图声并茂的动画程序
- CSS网页标准制作关于网页表单语义结构实例
- OSG例程(3) - 利用更新回调制作路径动画
- Visual C# 2005 - 利用程序代码制作简单动画效果
- MATLAB GUI中利用定时器制作动画
- 利用CSS和javascript实现Google首页的动画效果
- 【百度地图API】如何利用地图API制作汽车沿道路行驶的动画
- 利用float制作兼容ie6纯css下来菜单,无table、无js