javascript - JQuery : how to hide div after animation? - Stack Overflow

I would like to hide dive after the animation. Is it possible ?I can show you code here$(document).read

I would like to hide dive after the animation. Is it possible ?

I can show you code here

$(document).ready(function() {
  $('button').click(function() {
    var $lefty = $(this).next();
    $lefty.animate({
      left: parseInt($lefty.css('left'),10) == 0 ?
        -$lefty.outerWidth() :
        0
    });
  });
});​

Demo

I would like to hide dive after the animation. Is it possible ?

I can show you code here

$(document).ready(function() {
  $('button').click(function() {
    var $lefty = $(this).next();
    $lefty.animate({
      left: parseInt($lefty.css('left'),10) == 0 ?
        -$lefty.outerWidth() :
        0
    });
  });
});​

Demo

Share Improve this question asked Apr 2, 2012 at 13:59 Mo.Mo. 27.6k36 gold badges166 silver badges233 bronze badges 2
  • Which <div> do you want to hide? #main? Or do you want to remove the <div> that was animated entirely? – Ry- Commented Apr 2, 2012 at 14:01
  • @minitech i need to hide div1 to show div2 – Mo. Commented Apr 2, 2012 at 14:04
Add a ment  | 

3 Answers 3

Reset to default 2

Pass a callback to animate as the second argument. Also, you'll need to change .next() to something else to find only the first child, and there are a few other optimizations that can be made. Your CSS is also wrong. Here's the updated jsFiddle.

$(document).ready(function() {
    $('button').click(function() {
        var $lefty = $(this).next().children().eq(0);

        $lefty.animate({
            left: -$lefty.outerWidth()
        }, function() {
            $lefty.next().show();
            $lefty.remove();
        });
    });
});​

As a fourth param, animate can take a callback to execute on plete. Alternatively, just use a plete attribute on your options object.

$(document).ready(function () {
    $('button').click(function () {
        var $lefty = $(this).next();
        $lefty.animate({
            left: (parseInt($lefty.css('left'), 10) == 0 ? -$lefty.outerWidth() : 0),
            plete: function () {
                /* Do hide here */
            }
        });
    });
});

Hide the div in there perhaps by calling hide() on this.

You can pass a callback to be called on pletion:

$(document).ready(function() {
  $('button').click(function() {
    var $lefty = $(this).next();
    $lefty.animate({
      left: parseInt($lefty.css('left'),10) == 0 ?
        -$lefty.outerWidth() :
        0
    }, function () {
      $lefty.hide();
    });
  });
});​

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745342709a4623401.html

相关推荐

  • javascript - JQuery : how to hide div after animation? - Stack Overflow

    I would like to hide dive after the animation. Is it possible ?I can show you code here$(document).read

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信