我要珍惜我的爱

经历过这么多的事情,才发现真正的离不开我的小立立。我应该多谅解她,多包容她,多关心她,多关心她。这世界没有别的女人了,只有我的小立立是我的最爱。珍惜爱我的人,去好好爱我的小立立。 我们的幸福要共同创建吧,以此作为我们的奋斗目标吧!同舟共济,爱你一万年!
为了实现“弹窗一直留着不会消失”的效果,我们只需要移除原有的定时器和动画隐藏逻辑即可。以下是修改后的完整代码示例: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>自适应大小弹窗</title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #111; } .popup { position: fixed; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: bold; color: white; z-index: 1000; text-align: center; box-sizing: border-box; padding: 10px; background-color: rgba(255, 255, 255, 0.9); border-radius: 10px; } </style> </head> <body> <script> const messages = [ "你真棒!", "加油哦!", "别担心,一切都会好起来的。", "我支持你!", "你是最好的!", "谢谢你一直努力。", "今天也要开心!", "我相信你能做到!", "你值得被和被珍惜。", "继续向前,不要放弃!" ]; function showAdaptiveMessage() { const message = messages[Math.floor(Math.random() * messages.length)]; const popup = document.createElement("div"); popup.className = "popup"; popup.textContent = message; // 创建一个临时元素用于测量文本尺寸 const tempDiv = document.createElement("div"); tempDiv.style.position = "absolute"; tempDiv.style.visibility = "hidden"; tempDiv.style.whiteSpace = "pre-wrap"; tempDiv.style.wordWrap = "break-word"; tempDiv.style.font = getComputedStyle(popup).font; tempDiv.textContent = message; document.body.appendChild(tempDiv); // 获取文本的实际尺寸 const width = tempDiv.offsetWidth + 20; // 加上一些内边距 const height = tempDiv.offsetHeight + 20; // 设置弹窗大小为文本的实际尺寸 popup.style.width = `${width}px`; popup.style.height = `${height}px`; // 随机位置 const left = Math.random() * (window.innerWidth - width); const top = Math.random() * (window.innerHeight - height); popup.style.left = `${left}px`; popup.style.top = `${top}px`; // 清除临时元素 document.body.removeChild(tempDiv); document.body.appendChild(popup); } // 每秒显示一条消息(但不会自动关闭) setInterval(showAdaptiveMessage, 1000); </script> </body> </html> ``` ### 功能说明: 1. **弹窗不会再自动消失**:去掉了 `setTimeout` 和移除弹窗的逻辑。 2. 弹窗会根据内容动态调整大小,并随机分布在屏幕上。 3. 所有弹窗会持续保留在页面中,形成叠加效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值