见缝插针(js基础)


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style media="screen">

body {

margin: 0px;

padding: 0px;

}

.wrap {

width: 400px;

height: 400px;

/*border: 1px solid black;*/

position: relative;

}

.center {

width: 50px;

height: 50px;

position: absolute;

top: 175px;

left: 175px;

background: black;

/*border: 25px solid black;*/

border-radius: 50%;

}

.ball {

width: 26px;

height: 26px;

background: black;

border-radius: 50%;

position: absolute;

top: -26px;

left: -12px;

}

.newball {

width: 26px;

height: 26px;

background: black;

border-radius: 50%;

position: absolute;

top: -26px;

left: -12px;

}

.line {

width: 2px;

height: 124px;

background: black;

position: absolute;

top: 76px;

left: 199px;

transform-origin: 50% 100%;

}

.box {

width: 400px;

height: 600px;

border: 1px solid black;

background: rgb(224, 224, 224);

overflow: hidden;

/*text-align: center;*/

/*line-height: 40px;*/

/*font-size: 40px;*/

}

.start {

width: 400px;

height: 600px;

background: rgba(0, 0, 0, 0.7);

position: absolute;

top: 1px;

left: 1px;

text-align: center;

line-height: 600px;

font-size: 40px;

color: rgb(214, 206, 206);

}

.startBtn {

width: 150px;

height: 60px;

border: 2px solid gray;

position: absolute;

top: 350px;

left: 125px;

background: rgba(188, 188, 188, 0.8);

border-radius: 20px;

text-align: center;

line-height: 60px;

font-size: 25px;

color: rgb(88, 100, 100);

cursor: pointer;

}

.num {

width: 26px;

height: 26px;

background: black;

color: white;

border-radius: 50%;

margin-left: 187px;

margin-top: 5px;

text-align: center;

line-height: 26px;

font-size: 15px;

}

.over{

width: 400px;

height: 600px;

background: rgba(0, 0, 0, 0.7);

position: absolute;

top: 1px;

left: 1px;

text-align: center;

line-height: 600px;

font-size: 40px;

color: rgb(214, 206, 206);

display: none;

}

.again{

width: 150px;

height: 60px;

border: 2px solid gray;

position: absolute;

top: 350px;

left: 125px;

background: rgba(188, 188, 188, 0.8);

border-radius: 20px;

text-align: center;

line-height: 60px;

font-size: 25px;

color: rgb(88, 100, 100);

cursor: pointer;

}

.niu{

width: 400px;

height: 600px;

background: rgba(0, 0, 0, 0.7);

position: absolute;

top: 1px;

left: 1px;

text-align: center;

line-height: 600px;

font-size: 200px;

color: rgb(214, 206, 206);

display: none;

}

</style>

</head>

<body>

<div class="box"></div>

<div class="start">

见缝插针<br>

<div class="startBtn">START</div>

</div>

<div class="over">

游戏结束

<!-- <div class="again">AGAIN</div> -->

</div>

<div class="niu">

牛逼

</div>

</body>

<script type="text/javascript">

var start = document.querySelector('.start');

var startBtn = document.querySelector('.startBtn');

startBtn.onclick = function() {

start.style.display = 'none';

}

var body_ = document.querySelector('.box');

var wrap = document.createElement('div');

wrap.className = 'wrap';

body_.appendChild(wrap);

var center = document.createElement('div');

center.className = 'center';

body_.appendChild(center);

var index = 1;

var x = 5;

var arr = [];

function made(){

for (var i = 0; i < x; i++) {

var line = document.createElement('div');

line.className = 'line';

line.setAttribute('id', 'init-line' + (i + 1) + '');

line.style.transform = 'rotate(' + i * (360 / x) + 'deg)';

arr.push(i * 360 / x);

console.log(arr);

var ball = document.createElement('div');

ball.className = 'ball';

line.appendChild(ball);

wrap.appendChild(line);

}

}

var timer = null;

var z = 0;

timer = setInterval(function() {

z++;

wrap.style.transform = 'rotate(' + z + 'deg)';

wrap.style.transformOrigin = '50% 50%';

if (z >= 360) {

z = 0;

} else {

z++;

}

}, 20)

body_.onclick = function() {

var newline = document.createElement('div');

newline.className = 'newline';

newline.style.width = '2px';

newline.style.height = '124px';

newline.style.background = 'black';

newline.style.position = 'absolute';

newline.style.left = '199px';

newline.style.top = '76px';

newline.style.transformOrigin = '50% 100%';

var newZ = 180 - z;

if (newZ <= 0) {

arr.push(newZ + 360)

} else {

arr.push(newZ);

}

// console.log(arr);

newline.style.transform = 'rotate(' + newZ + 'deg)';

var newball = document.createElement('div');

newball.className = 'newball';

newline.appendChild(newball);

wrap.appendChild(newline);

for (var i = 0; i < arr.length - 1; i++) {

if (Math.abs(arr[i] - arr[arr.length - 1]) <= 10) {

clearInterval(timer);

gameover();

}

}

var mm=0;

var nums=document.querySelectorAll('.num');

body_.removeChild(nums[mm]);

console.log(nums.length);

if (nums.length==1) {

next();

}

}

var c = 10;

for (var i = 0; i < c; i++) {

var num = document.createElement('div');

num.className = 'num';

num.innerHTML =c-i;

body_.appendChild(num);

}

var niu=document.querySelector('.niu');

function next(){

clearInterval(timer);

niu.style.display='block';

}

made();

var over=document.querySelector('.over');

function gameover(){

over.style.display='block';

}

</script>

</html>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值