淡入 jquery div 显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16079005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:21:50  来源:igfitidea点击:

Fade in jquery div show

javascriptjquerydelayfadeinfadeout

提问by Pete Naylor

I am trying to get the below script to fade in and fade out with a delay in between. It shows the div correctly and fades out as it should, but it doesn't fade in?

我试图让下面的脚本淡入和淡出,中间有延迟。它正确显示 div 并按应有的方式淡出,但没有淡入?

<?php
if(isset($_GET['updated'])) { ?>
<div id='updated'><p>The product was successfully added to your Shopping Cart</p></div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$('#updated').fadeIn(800).delay(3000).fadeOut(800)
</script>
<?php } ?>

Many thanks!

非常感谢!

回答by dt192

its because its already showing

因为它已经显示

<div id='updated' style="display:none">

fixes it

修复它

回答by ahren

$('#updated').hide().fadeIn(800).delay(3000).fadeOut(800);

You could also set it in the css:

你也可以在css中设置:

#updated{
  display: none;
}

The problem is - it's already visible (by default).

问题是 - 它已经可见(默认情况下)。

回答by Adil

You have to hidedivbefore fadeIn(), you can use hide()method to hide the div.

你必须隐藏div之前fadeIn(),你可以使用hide()方法来隐藏div

<?php
if(isset($_GET['updated'])) { ?>
<div id='updated'><p>The product was successfully added to your Shopping Cart</p></div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">

$('#updated').hide().fadeIn(800).delay(3000).fadeOut(800)
</script>
<?php } ?>