[ACCEPTED]-How to run jQuery fadeIn() and slideDown() simultaneously?-jquery

Accepted answer
Score: 157

Use animate() instead of fadeIn():

$(this)
  .css('opacity', 0)
  .slideDown('slow')
  .animate(
    { opacity: 1 },
    { queue: false, duration: 'slow' }
  );

0

Score: 5

start with height:0px and opacity:0; filter: alpha(opacity = 0) then on the action do:

$(this).stop().animate({
    height: 200,
    opacity: 1
}, 350);

Change 2 the height (i set to 200) and the duration 1 (i set to 350) to whatever you want.

Score: 5

Here is my solution, you can use it as a 4 jQuery plugin.

(function($) {
    'use strict';
    // Sort us out with the options parameters
    var getAnimOpts = function (a, b, c) {
            if (!a) { return {duration: 'normal'}; }
            if (!!c) { return {duration: a, easing: b, complete: c}; }
            if (!!b) { return {duration: a, complete: b}; }
            if (typeof a === 'object') { return a; }
            return { duration: a };
        },
        getUnqueuedOpts = function (opts) {
            return {
                queue: false,
                duration: opts.duration,
                easing: opts.easing
            };
        };
    // Declare our new effects
    $.fn.showDown = function (a, b, c) {
        var slideOpts = getAnimOpts(a, b, c), fadeOpts = getUnqueuedOpts(slideOpts);
        $(this).hide().css('opacity', 0).slideDown(slideOpts).animate({ opacity: 1 }, fadeOpts);
    };
    $.fn.hideUp = function (a, b, c) {
        var slideOpts = getAnimOpts(a, b, c), fadeOpts = getUnqueuedOpts(slideOpts);
        $(this).show().css('opacity', 1).slideUp(slideOpts).animate({ opacity: 0 }, fadeOpts);
    };
}(jQuery));

Now you can use it the same 3 way you would use jQuery’s .fadeIn (or fadeOut) effect.

// Show
$('.alert').showDown('slow');
// Hide
$('.alert').hideUp('fast', function() {
    // Animation complete: '.alert' is now hidden
});

This 2 will resize our element’s height with a 1 fading effect.

It was originally posted on my blog.

Score: 4
$('.target')                    
    .hide()  
    .slideDown(500, 'swing')  
    .css('opacity', 0)  
    .animate({opacity: 1}, {queue: false, duration: 1000});

0

Score: 3

The more modern solution is to use values 1 of 'show' and 'hide' when you want to combine animations:

$('.show').on('click', function () {
  $('.example').animate({
    opacity: 'show',
    height: 'show',
    marginTop: 'show',
    marginBottom: 'show',
    paddingTop: 'show',
    paddingBottom: 'show'
  })
})
$('.hide').on('click', function () {
  $('.example').animate({
    opacity: 'hide',
    height: 'hide',
    marginTop: 'hide',
    marginBottom: 'hide',
    paddingTop: 'hide',
    paddingBottom: 'hide'
  })
})
.example {
  background-color: blue;
  height: 200px;
  width: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
  <button type="button" class="show">Show</button>
  <button type="button" class="hide">Hide</button>
</p>
<div class="example"></div>
Score: 1
        $(document).ready(function() {
    $("#test").bind("click", function() {
            setTimeout(function() {
            $('#slidedown').slideDown("slow");
        }, 500);
        $("#content").fadeOut(500);
        $(this).stop().animate({ "opacity": "1" }, "slow");
        });
    });

this is for fade out but i think it's what 2 your after. please have a look at the example 1 too: http://jsfiddle.net/oddacon/M44md/

Score: 0

It's possible now to use CSS3 transitions. It 1 allows to achieve very flexible solutions.

HTML

<div id="btn">Click me</div>
<div id="hidden"></div>

CSS

#hidden {
    display: none; opacity: 0; height: 100px; background: red;
    transition: opacity 600ms ease-in-out 0s;
}
#hidden.opened {
    opacity: 1;
}

jQuery

$('#btn').click(function() {
    var div = $('#hidden');
    if ( ! div.is(':animated')) {
        div.slideToggle(600).toggleClass('opened');
    }
});

More Related questions