[英]Fade in Bootstrap Alert is not working
I am trying to implement an alert
using Twitter Bootstrap
however I am having a lot of difficulty in getting it to fade in when the user loads the page. 我正在尝试使用
Twitter Bootstrap
实施alert
但是当用户加载页面时,要使其淡入,我遇到了很多困难。 Basically this is the code so far: 基本上,这是到目前为止的代码:
<div class="alert alert-success fade alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>Welcome!</strong> Administrator...
</div>
.fade {
opacity: 0;
-webkit-transition: opacity 0.15s linear;
-moz-transition: opacity 0.15s linear;
-o-transition: opacity 0.15s linear;
transition: opacity 0.15s linear;
}
.fade.in {
opacity: 1;
}
$(document).ready(function(){
showAlert();
});
function showAlert(){
$(".close").addClass("in")
}
But when I load the page the Alert
cannot be seen, I'm wondering what I am doing wrong? 但是,当我加载页面时,看不到
Alert
,我想知道我在做什么错?
@ My comment above, it looks like you're adding the class to the child, and not the parent. @上面的我的评论,看来您是在向孩子而不是父母添加班级。
If you're using jquery, you could explore using more of it http://jsfiddle.net/evanbriggs/6us0dLyL/ 如果您使用的是jquery,则可以探索使用更多的方法http://jsfiddle.net/evanbriggs/6us0dLyL/
or just have it add a class where a fadeIn
animation is stored http://jsfiddle.net/evanbriggs/1gr9k0sq/ . 或者只是添加一个类,其中会存储一个
fadeIn
动画http://jsfiddle.net/evanbriggs/1gr9k0sq/ 。 Your preference! 您的喜好!
You should add the class to the div with the "fade" class: 您应该使用“ fade”类将类添加到div中:
$(".fade").addClass("in")
Not to the button inside it. 不去里面的按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.