原生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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM