javascript实现弹窗

<!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>弹窗</title>
    <style>
        *{
    
    
            margin:0px;
            padding:0px;
        }
        #container{
    
    
            position:absolute;
            top:50%;
            left:50%;
            margin-left:-50px;
            margin-top:-15px;
            width:100px;
            height:50px;
            text-align:center;
            line-height:50px;
            background-color:mediumorchid;
            border-radius:15px;
            opacity:0;
            transition:1s;
        }
    </style>
</head>
<body>
    <div id="container">弹窗</div>
    <script>
        const div = document.getElementById("container")
        function popup(){
    
    
            setTimeout(function(){
    
    
                div.style.marginTop = "-15px"
                div.style.opacity = 0
            }, 500) 
            setTimeout(function(){
    
    
                div.style.marginTop = "-100px"
                div.style.opacity = 1
            }, 1000)    
            setTimeout(function(){
    
    
                div.style.marginTop = "-200px"
                div.style.opacity = 0
            }, 2000) 
            // setTimeout(function(){
    
    
            //     div.style.marginTop = "-15px"
            //     // div.style.opacity = 0
            // },1)
        }
        setInterval(function(){
    
    
            popup()
        },2500)
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_48727085/article/details/118341232