每次使用电脑都看到的开机动画,你知道怎么做出来的吗

导读:本篇文章讲解 每次使用电脑都看到的开机动画,你知道怎么做出来的吗,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

先看图,这个是不是很面熟呀!

每次使用电脑都看到的开机动画,你知道怎么做出来的吗

直接上代码看效果

<!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>
    <style>
        body {
            overflow: hidden;
        }
        
        .s {
            position: absolute;
            top: 376px;
            right: 0;
        }
        
        .x {
            position: absolute;
            top: 620px;
            right: 0;
        }
        
        .box span {
            display: block;
            width: 20px;
            height: 20px;
            position: absolute;
            bottom: 324px;
            right: 10px;
            background-color: transparent;
            z-index: 10;
        }
    </style>
</head>

<body>
    <div class="box">
        <span></span>
        <img src="../images/t.jpg" alt="" class="s">
        <img src="../images/b.jpg" alt="" class="x">
    </div>
    <script>
        var btn = document.querySelector('span');
        var shang = document.querySelector('.s');
        var xia = document.querySelector('.x');
        btn.addEventListener('click', function() {

            animate2(shang, shang.offsetTop + 143, function() {
                animate(shang, shang.offsetLeft + 325)
            });
            animate2(xia, xia.offsetTop + 101, function() {
                animate(xia, xia.offsetLeft + 325)
            });
        })

        //往下
        function animate2(obj, target, callback) {
            clearInterval(obj.timer);
            obj.timer = setInterval(function() {
                var step = (target - obj.offsetTop) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                if (obj.offsetTop == target) {
                    clearInterval(obj.timer);
                    if (callback) {
                        //调用函数
                        callback();
                    }
                }
                obj.style.top = obj.offsetTop + step + 'px';
            }, 15)
        }


        //往右
        function animate(obj, target, callback) {
            clearInterval(obj.timer);
            obj.timer = setInterval(function() {
                var step = (target - obj.offsetLeft) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                if (obj.offsetLeft == target) {
                    clearInterval(obj.timer);
                    if (callback) {
                        //调用函数
                        callback();
                    }
                }
                obj.style.left = obj.offsetLeft + step + 'px';
            }, 15)
        }
    </script>
</body>

</html>

效果你一定是见过的

 每次使用电脑都看到的开机动画,你知道怎么做出来的吗

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/6277.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!