网页弹窗 HTML+JS+CSS实现白色简约风格弹窗公告
导读:如何设计网页弹窗公告的 HTML 代码,以实现白色简约风格。该代码以简洁的白色为主调,搭配清晰的排版和醒目的字体,可以高效传递公告信息,适用于产品更新通知和活动推广等场景。文章中还提供了每小时弹出一次的设置,以及三个按钮“关闭弹窗”、"跳转连接"、“子选项”。前言设计网页弹窗公告时,既要简约又要醒目?这里有一份白色简约弹窗公告 HTML...
如何设计网页弹窗公告的 HTML 代码,以实现白色简约风格。该代码以简洁的白色为主调,
搭配清晰的排版和醒目的字体,可以高效传递公告信息,适用于产品更新通知和活动推广等场景。
文章中还提供了每小时弹出一次的设置,以及三个按钮“关闭弹窗”、"跳转连接"、“子选项”。
前言
设计网页弹窗公告时,既要简约又要醒目?这里有一份白色简约弹窗公告 HTML 代码,
它以简洁的白色为主调,搭配清晰的排版和醒目的字体,轻松实现公告信息的高效传递。
不管是产品更新通知,还是活动推广,都能完美适配,为你的网页增添一份简洁之美。
功能
三个按钮“关闭弹窗”、"跳转连接"、“子选项”,每小时弹出一次
代码
HTML
<div id="popup" class="popup"> <div class="popup-container"> <div class="popup-content"> <span class="close" aria-label="关闭弹窗">×</span> <div class="popup-header"> <p class="popup-note">每小时弹出一次,可设置弹出时间</p> <h2>欢迎来访~</h2> <p class="popup-desc">很高兴你的来访,不过您在了解我们的业务之前可以先进论坛或咨询客服,当然你已轻车熟路请无视我~</p> <div class="buttons"> <a href="https://jk.lyszm.com"popup-btn qq-group" target="_blank" rel="noopener noreferrer">交流论坛</a> <div class="popup-btn contact-us"> 联系客服 <div class="contact-dropdown"> <div class="contact-option" data-type="qq" data-value="11598716">QQ</div> <div class="contact-option" data-type="wechat" data-href="https://www.hackyh.com">微信</div> <div class="contact-option" data-type="tg" data-value="Martin_rmgy" data-href="https://t.me">TG</div> </div> </div> </div> </div> </div> </div> </div>>
JS
//www.hackyh.com
document.addEventListener('DOMContentLoaded', function() {
const popup = document.getElementById('popup');
const closeBtn = popup.querySelector('.close');
const contactBtn = popup.querySelector('.contact-us');
const dropdown = popup.querySelector('.contact-dropdown');
// 创建复制成功提示元素
const copySuccess = document.createElement('div');
copySuccess.className = 'copy-success';
document.body.appendChild(copySuccess);
// 复制文本函数
async function copyText(text, type) {
try {
await navigator.clipboard.writeText(text);
let message = '复制成功!';
if (type === 'qq') {
message = `已复制QQ号"${text}"`;
} else if (type === 'tg') {
message = `已复制TG号"${text}"`;
}
copySuccess.textContent = message;
copySuccess.classList.add('show');
setTimeout(() => {
copySuccess.classList.remove('show');
}, 1500);
} catch (err) {
console.error('复制失败:', err);
copySuccess.textContent = '复制失败,请手动复制';
copySuccess.classList.add('show');
setTimeout(() => {
copySuccess.classList.remove('show');
}, 1500);
}
}
// 处理联系方式点击事件
document.querySelectorAll('.contact-option').forEach(option => {
option.addEventListener('click', async (e) => {
e.stopPropagation(); // 阻止事件冒泡
const type = option.dataset.type;
const value = option.dataset.value;
const href = option.dataset.href;
if (value) {
await copyText(value, type);
// 如果是QQ选项,打开QQ对话链接
if (type === 'qq') {
window.open(`tencent://message/?uin=${value}`, '_self');
}
// 如果是TG选项,延迟3秒后打开链接
else if (type === 'tg' && href) {
setTimeout(() => {
window.open(href, '_blank');
}, 3000);
} else if (href) {
window.open(href, '_blank');
}
} else if (href) {
window.open(href, '_blank');
}
// 点击选项后关闭下拉菜单
dropdown.classList.remove('active');
});
});
// 联系客服按钮点击事件
contactBtn.addEventListener('click', (e) => {
e.stopPropagation(); // 阻止事件冒泡
dropdown.classList.toggle('active');
});
// 点击页面其他地方关闭下拉菜单
document.addEventListener('click', () => {
dropdown.classList.remove('active');
});
// 显示弹窗
function showPopup() {
if (!localStorage.getItem('lastPopupTime') ||
Date.now() - localStorage.getItem('lastPopupTime') > 3600000) {
popup.style.display = 'block';
localStorage.setItem('lastPopupTime', Date.now());
}
}
// 关闭弹窗
function closePopup() {
popup.classList.add('closing');
setTimeout(() => {
popup.style.display = 'none';
popup.classList.remove('closing');
}, 300);
}
// 绑定关闭按钮点击事件
closeBtn.addEventListener('click', closePopup);
// 显示弹窗
showPopup();
});
//也可以直接调用本站JS
<script defer src="https://www.hackyh.com/Project/tanchuang.js"></script>
CSS
.popup {
display: none;
position: fixed;
z-index: 9999;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
animation: fade-in 0.3s ease-out forwards;
}
.popup-container {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.popup-content {
background: linear-gradient(145deg, #ffffff, #f0f0f0);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 15px;
width: 90%;
max-width: 450px;
padding: 30px;
position: relative;
transform: scale(0);
animation: scale-in 0.4s ease-out forwards;
}
.popup-header {
text-align: center;
}
.popup-note {
color: #ff4757;
font-size: 0.9em;
margin: 0 0 15px 0;
}
.popup-desc {
color: #666;
font-size: 1.1em;
line-height: 1.6;
margin: 15px 0;
}
h2 {
color: #1a1a1a;
font-size: 2em;
font-weight: 600;
margin: 15px 0;
letter-spacing: -0.5px;
}
.buttons {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 25px;
}
.popup-btn {
padding: 12px 25px;
border-radius: 8px;
color: #ffffff;
font-size: 1.1em;
font-weight: 500;
text-decoration: none;
transition: all 0.3s ease;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.qq-group {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
.contact-us {
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
}
.popup-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.close {
position: absolute;
right: 20px;
top: 15px;
color: #666;
font-size: 24px;
font-weight: 300;
cursor: pointer;
transition: all 0.2s ease;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
}
.close:hover {
color: #ff4757;
background-color: rgba(0, 0, 0, 0.05);
transform: rotate(90deg);
}
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes scale-in {
from { transform: scale(0.8); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
@media (max-width: 480px) {
.popup-content {
margin: 0 20px;
padding: 25px;
}
.buttons {
flex-direction: column;
gap: 10px;
}
h2 {
font-size: 1.8em;
}
.popup-desc {
font-size: 1em;
}
}
/* å¼¹çª—å…³é—æŒ‰é’® */
.close {
position: absolute;
right: 15px;
top: 15px;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
border: 2px solid transparent;
}
.close::before,
.close::after {
content: '';
position: absolute;
width: 20px;
height: 2px;
background-color: #666;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.close::before {
transform: rotate(45deg);
}
.close::after {
transform: rotate(-45deg);
}
.close:hover {
background: #ff4757;
transform: rotate(180deg) scale(1.1);
box-shadow: 0 4px 12px rgba(255, 71, 87, 0.2);
border-color: rgba(255, 255, 255, 0.8);
}
.close:hover::before,
.close:hover::after {
background-color: white;
}
/* æ·»åŠ å…³é—动画 */
@keyframes close-popup {
0% {
transform: scale(1) rotate(0);
opacity: 1;
}
50% {
transform: scale(1.2) rotate(45deg);
opacity: 0.5;
}
100% {
transform: scale(0) rotate(90deg);
opacity: 0;
}
}
/* 修改弹窗关é—动画 */
.popup.closing {
animation: fade-out 0.3s ease-out forwards;
}
.popup.closing .popup-content {
animation: close-popup 0.3s ease-out forwards;
}
@keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}
/* è”系客æœä¸‹æ‹‰èœå•æ ·å¼ */
.contact-us {
position: relative;
cursor: pointer;
}
.contact-dropdown {
display: none;
position: absolute;
top: 100%;
left: 0;
width: 100%;
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
margin-top: 5px;
overflow: hidden;
z-index: 10001;
}
.contact-dropdown.active {
display: block;
}
.contact-option {
padding: 10px 15px;
color: #333;
transition: all 0.3s ease;
cursor: pointer;
}
.contact-option:hover {
background: #f5f5f5;
}
/* æˆåŠŸæç¤ºæ ·å¼ */
.copy-success {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 10px 20px;
border-radius: 4px;
z-index: 10000;
display: none;
}
.copy-success.show {
display: block;
animation: fadeInOut 1.5s ease forwards;
}
@keyframes fadeInOut {
0% { opacity: 0; }
20% { opacity: 1; }
80% { opacity: 1; }
100% { opacity: 0; }
}也可以直接调用本站CSS
<link rel="stylesheet" type="text/css" href="https://www.hackyh.com/Project/tanchuang.css">
Hackyh'Blog版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

