原生JS实现消息提示框

  

 

复制代码
<!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>
        .popupStyle{
            width:260px;
            height:80px;
            background-color: rgb(85,85,85);            
            /* display:none; */
            color:#fff;
            text-align:center;
            line-height:80px;
            border-radius:20px;
            padding:8px 0;
            position:fixed;
            z-index:1;
            top:2%;
            left:50%;
            transform:translateX(-50%);
        }
        .popupStyle::after{
            content:"after";
            color:black;
            position:absolute;
            top:100%;
            left:50%;
            transform:translateX(-50%);
            border-width:10px;
            line-height:15px;
            border-style:solid;
            border-color:rgb(1, 0, 5) transparent transparent transparent;
        }
    </style>
</head>
<body style="text-align:center;">
    <h2 style="margin-top:200px;">Pop Up</h2>
    <div style="text-align:center;">
        <a href="#" onclick="stylePopup(styleMsg)">stylePopup</a>
        <a href="#" onclick="domPopup(domMsg)">domPopup</a>
    </div>
    <span class="popupStyle" id="popup">popupStyle</span>
    <script>
        console.log(getComputedStyle(popup).display)
        const styleMsg='Popup of style'
        const domMsg='Popup of dom'
        function stylePopup(message){
            const popup=document.getElementById('popup')
            console.log(popup)
            popup.innerHTML=message || 'default messsage'
            popup.style.display='block'
            setTimeout(()=>{
                popup.style.display='none'
            },1000)
        }
        function domPopup(message){
            const span=document.createElement('span')
            span.innerHTML=message || 'default'
            span.className='popupStyle'
            span.style.display='block'
            document.body.appendChild(span)
            setTimeout(()=>{
                span.remove()
            },1000)
        }
    </script>
</body>
</html>
复制代码

 

posted @   ascertain  阅读(1068)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示