Make hidden div appear then fade away?

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:12:49

问题


What is the simplest way to make a div appear then fade a way for a few second?

.fade_div {
    visibility: none;
    position: fixed;
    background-color: yellow;
    border: 1px solid black;
    top: 300px;
    left: 300px
}
<input type="button" value="Add Item" id="mybutton">

<div class="fade_div">Successfully Added!</div>
$('mybutton').click(function(){
    $('.fade_div').....
}

回答1:


The following code will make the elements with .fade_div class fade in quickly, wait one second (1000ms) and fade out slowly.

$('#mybutton').click(function(){
    $('.fade_div').finish().fadeIn("fast").delay(1000).fadeOut("slow");
});

You might want to stop using visibility: hidden; (not none) and use display: none instead.

For an instant appearance instead of fade in:

$('#mybutton').click(function(){
    $('.fade_div').finish().show().delay(1000).fadeOut("slow");
});

jsFiddle Demo




回答2:


$('#btn').click(function(e){    
    $('#fancy').fadeOut('slow', function(){
        $('#bank').fadeIn('slow');
    });
});

FIDDLE DEMO




回答3:


Such a straight question:

use:

$(".fade_div").fadeOut(1500, someFunctionCallAfterFadeDone);

Read more about it here



来源:https://stackoverflow.com/questions/18812948/make-hidden-div-appear-then-fade-away

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!