gpt4 book ai didi

javascript - 怎么让通知消失

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:38 26 4
gpt4 key购买 nike

我未能发出将在大约 1 秒后消失的通知,同时让页面上的元素稍微变暗或褪色(看起来好像在背景中)。此处对 JavaScript 知之甚少。

var notification = document.getElementById("one");
setTimeout(function() {
notification.close()
}, 1000)
body {
background: rgba(0, 0, 0, 0.75);
}

.notification {
transition: all 0.35s;
position: absolute;
left: 0;
right: 0;
top: 0;
background: linear-gradient(#1abc9c, #16a085);
border-bottom: 0.125rem solid #1abc9c;
box-shadow: rgba(0, 0, 0, 0.4) 0 0.25rem 0.25rem 0;
}

.notification .content {
text-align: center;
color: #fff;
}
<div id="one" class="notification">
<div class="content">
<p>This is a notification</p>
</div>
</div>
<div class="wrapper">
<p>This is a text that i copied from someone: My father had a small estate in default link Nottinghamshire: I was the third of five sons. He sent me to Emanuel College in Cambridge at fourteen years old, where I resided three years, and applied myself
close to my studies; but the charge of maintaining me, although I had a very scanty allowance, being too great for a narrow fortune, I was bound apprentice to Mr. James Bates, an eminent surgeon in London, with whom I continued four years. </p>
</div>

最佳答案

您需要将 .close() 更改为 .style.visibility = 'hidden'

close() 函数不是用于隐藏 DOM 元素的原生 JavaScript 函数。

var notification = document.getElementById("one");
setTimeout(function() {
notification.style.visibility = 'hidden';
}, 1000)
body {
background: rgba(0, 0, 0, 0.75);
}

.notification {
transition: all 0.35s;
position: absolute;
left: 0;
right: 0;
top: 0;
background: linear-gradient(#1abc9c, #16a085);
border-bottom: 0.125rem solid #1abc9c;
box-shadow: rgba(0, 0, 0, 0.4) 0 0.25rem 0.25rem 0;
}

.notification .content {
text-align: center;
color: #fff;
}
<div id="one" class="notification">
<div class="content">
<p>This is a notification</p>
</div>
</div>
<div class="wrapper">
<p>This is a text that i copied from someone: My father had a small estate in default link Nottinghamshire: I was the third of five sons. He sent me to Emanuel College in Cambridge at fourteen years old, where I resided three years, and applied myself
close to my studies; but the charge of maintaining me, although I had a very scanty allowance, being too great for a narrow fortune, I was bound apprentice to Mr. James Bates, an eminent surgeon in London, with whom I continued four years. </p>
</div>

关于javascript - 怎么让通知消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48305623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com