Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery fade in while sliding down?

The script below does not fire the slideDown and fadeTo at the same time. It does not fade in until the slide down finishes.

    <script>
    $( document ).ready(function() {
        var obj = $("#example");
        obj.slideDown(450);
        obj.fadeTo(450,1);
    });
    </script>

How can I simultaneously slide the object down while also fading it in?

Also, the object is just a normal div.

like image 858
ThatGuy343 Avatar asked Mar 16 '23 18:03

ThatGuy343


2 Answers

When you use slideDown and fadeTo, both of these calls are added to a queue(fx queue) and is executed one after another.

You can use .animate() to animate a set of css properties

$(document).ready(function () {
    var obj = $("#example");
    obj.animate({
        opacity: 1,
        height: 'show'
    }, 450);
});

$(document).ready(function() {
  var obj = $("#example");
  obj.animate({
    opacity: 1,
    height: 'show'
  }, 450);
});
#example {
  display: none;
  opacity: 0;
  white-space: pre-line;
  border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="example">
$(document).ready(function () {
    var obj = $("#example");
    obj.slideDown(450);
    obj.fadeTo(450, 1);
});
</div>
like image 81
Arun P Johny Avatar answered Mar 27 '23 16:03

Arun P Johny


    obj.slideDown({duration: 450, queue: false});
    obj.stop().fadeTo(1000, 1);

Don't queue fadeTo(), fadeIn()/fadeOut()

like image 32
aadarshsg Avatar answered Mar 27 '23 16:03

aadarshsg