赞
踩
目录
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <style>
- .bdr1 {
- border-radius: 50%;
- width: 300px;
- height: 300px;
- border: 1px solid red;
- position: relative;
- }
-
- .bdr2 {
- border-radius: 50%;
- width: 200px;
- height: 200px;
- border: 1px solid green;
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- margin: auto;
- }
-
-
- .bdr3 {
- border-radius: 50%;
- width: 100px;
- height: 100px;
- border: 1px solid rebeccapurple;
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- margin: auto;
- }
-
- .bool {
- width: 50px;
- height: 50px;
- border-radius: 50%;
- background-color: skyblue;
- position: absolute;
- left: 0px;
- top: 125px;
- }
-
- .boolm {
- width: 50px;
- height: 50px;
- border-radius: 50%;
- background-color: rgb(226, 99, 99);
- position: absolute;
- left: 0px;
- top: 75px;
- }
- </style>
-
- <body>
- <div class="bdr1">
- <div class="bool" id="bool"></div>
- <div class="bdr2">
- <div class="boolm" id="boolm"></div>
- <div class="bdr3"></div>
- </div>
- </div>
- <button onclick="check()">开始</button>
- </body>
- <script>
- let bool = document.getElementById('bool')
- let boolm = document.getElementById('boolm')
- function check() {
- circleMove(bool, 0, 125, 125, 20)
- circleMove(boolm, 0, 75, 75, 20)
- }
- function circleMove(ball, x0, y0, r, t) {
- let x = 0, y
- let dsq1 = setInterval(() => {
- ball.style.left = x0 + x++ + 'px'
- y = -Math.sqrt(2 * x * r - Math.pow(x, 2))
- ball.style.top = y0 + y + 'px'
- if (x == 2 * r && y == 0) {
- clearInterval(dsq1)
- let dsq2 = setInterval(() => {
- ball.style.left = x0 + x-- + 'px'
- y = Math.sqrt(2 * x * r - Math.pow(x, 2))
- ball.style.top = y0 + y + 'px'
- if (x == 0 && y == 0) {
- clearInterval(dsq2)
- circleMove(ball, x0, y0, r, t)
- }
- }, t)
- }
- }, t)
- }
- </script>
-
- </html>

- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <style>
- img {
- width: 200px;
- height: 200px;
- float: left;
- }
-
- .picture {
- width: 1600px;
- height: 200px;
- position: relative;
- }
-
- .picture>div {
- position: absolute;
- }
-
- .kuang {
- width: 1600px;
- height: 200px;
- }
-
- .a {
- width: 200px;
- height: 200px;
- float: left;
- margin-left: 40px;
- border: 1px solid black;
- text-align: center;
- line-height: 200px;
- }
- </style>
-
- <body>
- <div class="picture">
- <div style="left: 0px;" id="picture1"><img src="图片/关羽.webp" alt="" onclick="move1()"></div>
- <div style="left: 200px;" id="picture2"><img src="图片/貂蝉.webp" alt="" onclick="move2()"></div>
- <div style="left: 400px;" id="picture3"><img src="图片/刘协.webp" alt="" onclick="move3()"></div>
- <div style="left: 600px;" id="picture4"><img src="图片/孙权.webp" alt="" onclick="move4()"></div>
- <div style="left: 800px;" id="picture5"><img src="图片/曹操.jpg" alt="" onclick="move5()"></div>
- <div style="left: 1000px;" id="picture6"><img src="图片/刘备(1).jpg" alt="" onclick="move6()"></div>
- </div>
- <hr>
- <div class="kuang">
- <div class="a">刘协</div>
- <div class="a">刘备</div>
- <div class="a">关羽</div>
- <div class="a">曹操</div>
- <div class="a">孙权</div>
- <div class="a">貂蝉</div>
- </div>
-
- </body>
- <script>
- function change(img, x, y) {
- document.onkeydown = function (e) {
- switch (e.keyCode) {
- //左
- case 37:
- x--
- img.style.left = x + 'px'
- console.log(1)
- break
- //右
- case 39:
- x++
- img.style.left = x + 'px'
- console.log(2)
- break
- //上
- case 38:
- y--
- img.style.top = y + 'px'
- break
- //下
- case 40:
- y++
- img.style.top = y + 'px'
- break
- }
- }
- }
- function move1() {
- change(picture1, 0, 0)
- }
- function move2() {
- change(picture2, 200, 0)
- }
- function move3() {
- change(picture3, 400, 0)
- }
- function move4() {
- change(picture4, 600, 0)
- }
- function move5() {
- change(picture5, 800, 0)
- }
- function move6() {
- change(picture6, 1000, 0)
- }
- </script>
-
- </html>

- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <title>Document</title>
- <style>
- .f {
- width: 1200px;
- height: 800px;
- border: 1px solid red;
- position: relative;
- }
-
- .z {
- width: 100px;
- height: 100px;
- border-radius: 50%;
- background-color: #6cf;
- position: absolute;
- /* 正中心 */
- left: 550px;
- top: 350px;
- }
-
- .kuai {
- position: relative;
- width: 400px;
- height: 20px;
- background-color: red;
- left: 0px;
- }
- </style>
- </head>
-
- <body>
- <div class="f" onclick="startgame()">
- <div id="ball" class="z">
- </div>
- </div>
- <div id="kuai" class="kuai"></div>
- </body>
- <script>
- //1、生成0到1200的随机整数
- let r = Math.floor(Math.random() * 1200)
- console.log(r)
- //小球球心着落的随机点坐标是(r,50)
- //小球球心坐标(x,y)
- let x = 600, y = 400
- //计算x和y之间运动距离的倍数关系
- let x_y = (x - r) / (y - 50)
- let dy = 1//表示 单位时间 内沿着y轴向上运动1
- let dx = x_y * dy//表示 单位时间 沿着x轴的位移
-
- //获取小球的dom对象
- let ball = document.getElementById('ball')
- let kuai = document.getElementById('kuai')
- let x1 = 0
- let a = 30
-
-
- //点击父元素任意位置,开始游戏
- function startgame() {
- setInterval(() => {
- //上下碰撞
- if (y <= 50) {
- dy = -dy
-
- }
- if (y >= 750 && x1 < x && x < x1 + 400) {
- console.log(x)
- console.log(x1)
- dy = -dy
- }
- //左右碰撞
- if (x <= 50 || x >= 1150) {
- dx = -dx
- }
- //把单位时间的位移作用在坐标上
- x += dx
- y += dy
- //把坐标作用在实际的定位上
- ball.style.left = x - 50 + 'px'
- ball.style.top = y - 50 + 'px'
- }, 1)
- }
- document.onkeydown = function (e) {
- switch (e.keyCode) {
- //左
- case 37:
- x1 -= a
- kuai.style.left = x1 + 'px'
- break
- //右
- case 39:
- x1 += a
- kuai.style.left = x1 + 'px'
- break
- }
- }
-
- </script>
-
- </html>

赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。