jQuery: FadeOut then SlideUp

萝らか妹 提交于 2019-11-27 17:27:39
jQuery.fn.fadeThenSlideToggle = function(speed, easing, callback) {
  if (this.is(":hidden")) {
    return this.slideDown(speed, easing).fadeTo(speed, 1, easing, callback);
  } else {
    return this.fadeTo(speed, 0, easing).slideUp(speed, easing, callback);
  }
};

I tested it on JQuery 1.3.2, and it does work.

Edit: This is the code I called it from. #slide-then-fade is the ID of a button element, article-text is a class on a div tag:

$(document).ready(function() {
  $('#slide-then-fade').click(function() {
    $('.article-text').fadeThenSlideToggle();
  });
});

Edit 2: Modified to use the built-in slideUp.

Edit 3: Rewritten as a toggle, and using fadeTo

Sounds like it would be better to use the jQuery fadeTo command

 $(function() {

     $("#myButton").click(function() {
         $("#myDiv").fadeTo("slow", 0.00, function(){ //fade
             $(this).slideUp("slow", function() { //slide up
                 $(this).remove(); //then remove from the DOM
             });
         });

     });

});

Working Demo here.

By performing each command in the callback function of the preceding command, the command will not run until the previous one completes; a "jump" occurs when the element is removed from the DOM without waiting for the slideUp to complete.

Can't you chain it?

$('myelement').fadeOut().slideUp();

EDIT:

Maybe this will help instead?

albert
$("#id").fadeIn(500, function () {

    $("#id2").slideUp(500).delay(800).fadeOut(400);

});

Try $('.row').animate({ height: 'toggle', opacity: 'toggle' }, 'slow').slideUp();

demo Here

The fadeOut function takes a second optional argument of a callback function, so you should be able to do something like this:

$('elementAbove').fadeOut(500, function() {
    $('elementBelow').slideUp();
});

EDIT: forgot to add the speed of the fadeOut as the first parameter

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