顶部通知栏显示和隐藏具有平滑效果
Top Notification Bar Show and Hide with smooth effect
如果我的服务器出现任何错误/警告,我需要显示和隐藏具有绝对位置的顶部通知栏 - DIV。
我只需要在发生错误时才显示此 BAR,并在几秒钟后隐藏它可能是 10 秒,并且效果流畅?
如何在 HTML、CSS/SCSS 和 Pure Javascript 中实现这一点。NO Javscript Frameworks :(
<div id="app-notification-bar" class="app-notification-bar app-error-message"></div>
SCSS,前缀是应用程序-
.#{$prefix}error-message {
font-family:Helvetica, Arial, sans-serif;
font-size:12px;
vertical-align:central;
color: #cc0000;
font-weight:bold;
}
.#{$prefix}notification-bar {
position: absolute;
z-index: 101;
top: 0;
left: 0;
right: 0;
background: #FFFFFF;
text-align: center;
line-height: 2.5;
overflow: hidden;
-webkit-box-shadow: 0 0 5px black;
-moz-box-shadow: 0 0 5px black;
box-shadow: 0 0 5px black;
}
@-webkit-keyframes slideDown {
0%, 100% { -webkit-transform: translateY(-50px); }
10%, 90% { -webkit-transform: translateY(0px); }
}
@-moz-keyframes slideDown {
0%, 100% { -moz-transform: translateY(-50px); }
10%, 90% { -moz-transform: translateY(0px); }
}
.cssanimations.csstransforms .#{$prefix}notification-bar {
-webkit-transform: translateY(-50px);
-webkit-animation: slideDown 2.5s 10.0s 1 ease forwards;
-moz-transform: translateY(-50px);
-moz-animation: slideDown 2.5s 10.0s 1 ease forwards;
}
.JS
document.getElementById('app-notification-bar').innerHTML = wrnMsg;
setTimeout(function(){ document.getElementById('app-notification-bar').innerHTML = ''; }, 3000);
Js
var d;
function error(message){
var d=document.getElementById("error");
d.innerHTML=message;
d.style.opacity="1";
window.setTimeout(function(){
d.style.opacity="0";
},5000);
}
error("a big bug");
Css:
#error{
opacity:0;
transition:all ease 2s;
background-color:red;
color:white;
}
目录:
<div id="error"></div>
看看这个
.CSS
body {
background: white;
}
div.error-content {
transition: all 0.5s linear;
width: 100%;
height: 70px;
line-height: 70px;
background-color:red;
text-align: center;
color:white;
top:-70px;
position:absolute;
}
div.error-content.active {
top:0px
}
#showError {
position: absolute;
top: 80px;
}
爪哇语
document.getElementById("showError").addEventListener("click", function() {
var className = document.getElementsByClassName('error-content')[0].className
document.getElementsByClassName('error-content')[0].className = className.concat(" active");
setTimeout(function() {
document.getElementsByClassName('error-content')[0].className = 'error-content'
},2000)
});
你应该把你的代码写成这个问题。这对您使用淡入时间和缓慢使用很有帮助。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
});
</script>
</head>
<body>
<p>Demonstrate fadeIn() with different parameters.</p>
<button>Click to fade in boxes</button><br><br>
<div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>
</body>
</html>
只需用这些笨拙的盒子替换您的加载div 即可
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 显示5秒后隐藏潜水
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 浮动页脚栏-使用Bootstrap隐藏
- Html页面上的多个Base64图像和平滑加载
- 在jquery中为显示/隐藏设置cookie
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 从var向代码隐藏函数传递值
- Image赢得't隐藏在滚动jQuery上
- 具有rowGrouping的数据表无法隐藏列
- Jquery隐藏未触发
- JavaScript 检查隐藏字段中的值并将其设置为隐藏字段值
- 如何使用javascript按类隐藏元素(平滑过渡)
- 如何使用幻灯片应用平滑的显示/隐藏效果在jQuery上切换
- 如何在显示/隐藏文本时实现平滑过渡
- 悬停时使用显示/隐藏 jquery 函数平滑过渡
- 为悬停时显示隐藏跨度的按钮创建平滑过渡
- 顶部通知栏显示和隐藏具有平滑效果
- 添加隐藏列表的平滑效果