I am using a javascript-based modal dialog. The dialog is fading in and fading out fine, but if I want the fadeout to be delayed by some seconds using delay(3000), it is not working. It simply never fades out. What could I be doing wrong? It's an MVC app.
function testingh(button) {
alert("DfdfdfF");
$('.error-notification').remove();
var $err = $('<div>').addClass('error-notification')
.html('<h2>Paolo is awesome</h2>(click on this box to close)')
.css('left', $(button).position().left);
$(button).after($err);
$err.fadeIn('slow');
$err.delay(3000).fadeOut('slow');
}
If you know of a more efficient way to delay(meaning postpone) the fading out, then let me know. Using delay(3000).fadeOut seemed most efficient to me?
CSS:
.error-notification {
background-color:#AE0000;
color:white;
cursor:pointer;
display: none;
padding:15px;
padding-top: 0;
position:absolute;
z-index:1;
font-size: 100%;
}
.error-notification h2 {
font-family:Trebuchet MS,Helvetica,sans-serif;
font-size:140%;
font-weight:bold;
margin-bottom:7px;
}
-
Did you try to debug it? With firebug or any other tool?Vinzenz– Vinzenz2010年10月11日 14:28:25 +00:00Commented Oct 11, 2010 at 14:28
-
That sequence works just fine in a simple test. You should post what the CSS looks like, and as @Vinzenz suggests you should use Firebug or some other debug tools to check what the element CSS looks like during the animation.Pointy– Pointy2010年10月11日 14:41:03 +00:00Commented Oct 11, 2010 at 14:41
-
I posted CSS. Note:fadeOut on its own does work... it's justt that after "delay" it doesnt fade out at allTPR– TPR2010年10月11日 16:13:10 +00:00Commented Oct 11, 2010 at 16:13
3 Answers 3
setTimeout(function() {
$err.fadeOut()
}, 3000);
answered Oct 11, 2010 at 14:26
Julio Santos
3,9052 gold badges29 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Vinzenz
well jQuery supports delay the way he showed it so I would try to figure out first what was wrong with that
Julio Santos
A simple hide().delay(500).show() failed for me a couple days ago. Apparently, it's common across the Internet.
Instead of writing
$err.delay(3000).fadeout('slow');
try writing
$err.fadeout('4000');
answered Oct 11, 2010 at 14:31
Wasim Karani
8,87010 gold badges58 silver badges100 bronze badges
Comments
Isn't that you have to queue-chain your delay? try this
$err.fadeIn('slow').delay(3000).fadeOut('slow');
1 Comment
Pointy
This should make no difference.
lang-js