少帅下飞机代码

<%--
  Created by IntelliJ IDEA.
  User: akai
  Date: 2024/9/30
  Time: 19:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<style>
    #person{
        /*display: flex;*/
        /*justify-content: center;*/
        /*align-items: center;*/
        /*height: 100vh;*/
        position: relative;

        border: 1px solid black;
        float: left;
        top: 50px;
        left: 600px;
    }
    #aircrift{
        position: relative;
        float: left;
        top:1px;
        left:1px;
    }
</style>
<body>

<div id="aircrift"><button onclick="fly()">飞机</button></div>
    <div id="person">士兵&nbsp;&nbsp;&nbsp;&nbsp;<b id="a"></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;士兵</div>
    <script>
        function fly() {
            let plane = document.getElementById("aircrift");
            let person = document.getElementById("person");

            if (plane && person) {
                let planeStyle = window.getComputedStyle(plane);
                let personStyle = window.getComputedStyle(person);

                let planeTop = parseInt(planeStyle.top, 10);
                let planeLeft = parseInt(planeStyle.left, 10);
                let personTop = parseInt(personStyle.top, 10);
                let personLeft = parseInt(personStyle.left, 10);

                function movePlane() {
                    if (planeTop < personTop - 30) {
                        planeTop += 1;
                        plane.style.top = planeTop + 'px';
                    } else {
                        if (planeLeft < personLeft+75) {
                            planeLeft += 1;
                            plane.style.left = planeLeft + 'px';
                        } else {
                            return;
                        }
                    }
                    requestAnimationFrame(movePlane);
                }
                movePlane();
                function movePerson() {
                    if (personTop<780){
                        personTop+=1;
                        person.style.top=personTop+'px'
                    }else {
                        return
                    }
                    requestAnimationFrame(movePerson)
                }
                setTimeout(function (){
                    movePerson()
                },6000)

                setTimeout(function() {
                    document.getElementById("a").innerText = "少帅";
                }, 5000);
            }

        }
    </script>
</body>
</html>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值