简体   繁体   中英

In Jquery, how can I make a div smoothly slide down from A to B so that another div fades in A?

I tried this:

$('#hidden_div').fadeIn();

But the div that I want to smoothly slide down, just teleports itself to its next position. (I want it to slide smoothly to it) Then this:

$('#sliding_div').animate({marginTop: '+=400px'},1000);
$('#hidden_div').fadeIn();

But I didn't get the right effect. How can you achieve that? Thanks in advance.

$('#sliding_div').animate({marginTop: '+=400px', opacity:1},1000);

和之前,将#sliding_div opacity设置为0

If I've understood the effect you're after, you need to fadeIn() the second div after the animate() has completed. You can use the callback parameter of animate() to do this:

$('#sliding_div').animate(
    { marginTop: '+=400px' },
    1000,
    function() {
        $('#hidden_div').fadeIn();
    }
);

这是一个更平滑的版本: http : //jsfiddle.net/W8AtL/4/

This fixes the jump from it being marginTop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM