无聊的产物--仿说剑中的一个小游戏
2017-02-19 00:00
253 查看
都是BUG 不过勉强玩玩可以啦
1.复制下面的代码
2.把图片保存到同一目录下(文件名修改成 'IMG_0124.JPG')
3.可以分享一下怎么BUG 补上 比如说第一次点击会跳的问题...
1.复制下面的代码
2.把图片保存到同一目录下(文件名修改成 'IMG_0124.JPG')
3.可以分享一下怎么BUG 补上 比如说第一次点击会跳的问题...
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> html, body { width: 100%; height: 100%; margin: 0; padding: 0; } body { perspective: 1000px; } .father { width: 1000px; height: 773px; background: url('IMG_0124.JPG') no-repeat; position: absolute; transform-style: preserve-3d; transition: all 5s; opacity: .8; } .son { height: 50px; width: 50px; background-color: white; position: absolute; left: 500px; top: 300px; border-radius: 50%; background: radial-gradient(rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, 0) 50%); cursor: pointer; } </style> </head> <body> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <div class="father"> <div class="son"></div> </div> <script> //用DOM设置body的perspectiveOrigin //第一次点击会有BUG document.body.style.perspectiveOrigin = '50% 50%' var tar = document.querySelectorAll('.son') //注册点击事件 for(var i=0;i<tar.length;i++){ tar[i].onclick = clickHandle } //记录点击次数 var clickCount=0 function clickHandle() { //计算perspectiveOrigin位置 var x2 = this.offsetWidth / 2 + this.offsetLeft var y2 = this.offsetHeight / 2 + this.offsetTop //用动画改变perspectiveOrigin位置 animate(x2, y2) clickCount++ } function animate(x2, y2) { tar[0].timer = setInterval(function () { var arr = document.body.style.perspectiveOrigin.split(' '); console.log(arr); var x = parseFloat(arr[0]) var y = parseFloat(arr[1]) var step1 = ( x2 - x ) / 10; var step2 = ( y2 - y ) / 10; step1 = step1 > 0 ? Math.ceil(step1) : Math.floor(step1); step2 = step2 > 0 ? Math.ceil(step2) : Math.floor(step2); document.body.style.perspectiveOrigin = (x + step1) + 'px ' + (y + step2) + 'px' if (x == x2 && y == y2) { clearInterval(tar[0].timer) } }, 15) } //获取墨迹和入口 var moji = document.getElementsByClassName('father'); var enter =document.querySelectorAll('.son') //随机入口位置,给墨迹3D定位 for (var i = 0; i < moji.length; i++) { moji[i].style.transform = 'translateZ(' + (i*2 - 30) * 1000 + 'px)' enter[i].style.top=parseInt(Math.random()*300)+200+"px" enter[i].style.left=parseInt(Math.random()*500)+234+"px" } //记数还有初始化步长 用来增加速度 var step = 50 var count =1 function move() { tar[1].timer=setInterval(function () { //让墨迹不断向屏幕(自己)过来的动画 for (var i = 0; i < moji.length; i++) { var num = (parseFloat(moji[i].style.transform.split('(')[1]) + step) moji[i].style.transform = 'translateZ(' + num + 'px)' //当计数一定时 增加墨迹过来的速度 if(i==1){ count++ if(count>200){ count=count-200; step=step+50 } } } //当第一个墨迹大于27000 认为游戏结束 获取得分 if(parseFloat(moji[0].style.transform.split('(')[1])>27000){ clearInterval(tar[1].timer) alert('得分:'+clickCount/15*100) } }, 50) } move() </script> </body> </html>
相关文章推荐
- 一个方向控制射击小游戏的代码分析!(AS1.0)
- 很有趣的一个小游戏--打企鹅
- 自己用java做的一个打飞机的小游戏
- 完成了S60一个无聊的程序,感觉时间都浪费了,不过还是有所收获的。
- 一个贪吃蛇小游戏 用 C WINAPI 写的
- 偶然找到一个两年前发表的小游戏,炒炒剩饭^_^
- 一个我大四写的俄罗斯方块的小游戏
- 一个小游戏
- 无聊了..又写了一个CollapsiblePanel控件
- 一个测试记忆力的小游戏
- 无聊的解决的一个问题
- 用GDI+画的一个小游戏。
- GooglePK,一个无聊又有趣的小工具
- 一个程序员寂寞无聊纷乱的一天(转)
- 无聊做了一个SQL SERVER的测试
- 040928,一个无聊的中秋。
- 自己写的一个JSP小游戏21点,记录一下
- Google比Baidu快(发一个无聊的帖)
- - -无聊中...打造一个服务器观测台简陋:包括内存使用率等等
- 发布一个耐玩的小游戏-点水果电脑版