您好,登錄后才能下訂單哦!
使用JavaScript實(shí)現(xiàn)一個彈窗功能?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
效果圖
代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>動畫消息彈窗</title> </head> <style> .message { -webkit-box-sizing: border-box; box-sizing: border-box; margin: 0; padding: 0; color: rgba(0, 0, 0, 0.85); font-size: 14px; font-variant: tabular-nums; line-height: 1.5715; list-style: none; -webkit-font-feature-settings: 'tnum'; font-feature-settings: 'tnum'; position: fixed; top: 8px; left: 0; z-index: 1010; width: 100%; pointer-events: none; } .message-notice { padding: 8px; text-align: center; -webkit-animation-name: MessageMoveOut; animation-name: MessageMoveOut; -webkit-animation-duration: 0.3s; animation-duration: 0.3s; } .message-content { color: #52c41a; display: inline-block; padding: 10px 16px; background: #fff; border-radius: 2px; -webkit-box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05); box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05); pointer-events: all; } @-webkit-keyframes MessageMoveOut { 0% { max-height: 0; padding: 0; opacity: 0; } 100% { max-height: 150px; padding: 8px; opacity: 1; } } @keyframes MessageMoveOut { 0% { max-height: 0; padding: 0; opacity: 0; } 100% { max-height: 150px; padding: 8px; opacity: 1; } } </style> <body > <div > <a href="#" rel="external nofollow" onclick="handleMessage()">點(diǎn)擊彈窗</a> </div> <div class="message" id="message"></div> <script> const msg = "我是彈框消息"; // 彈窗消息 function handleMessage(message = msg) { const parentDiv = document.createElement("div"); const div = document.createElement("div"); div.className = "message-content"; div.innerHTML = message; parentDiv.appendChild(div); parentDiv.className = "message-notice"; document.getElementById("message").appendChild(parentDiv); setTimeout(() => { parentDiv.remove(); }, 2000); } </script> </body> </html>
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。