jQuery slideDown() animation not working
Asked Answered
S

3

6

I'm trying to get jQuery's slideDown() animation to work, but in my case the text that should slide down, just appears .. How do I make it appear with the animation in place too ?

I tried manually specifying the speed too, but end result was the same.

HTML:

<section class="subscribe">
    <button id="submitBtn" type="submit">Subscribe</button>
    <p></p>
</section>

JavaScript:

$(function () {
    $("#submitBtn").click(function (event) {
        $(".subscribe p").html("Thanks for your interest!").slideDown({
                        duration: 4000
                    });
    });
});

JSFiddle: http://jsfiddle.net/ahmadka/A2mmP/

Seismography answered 10/7, 2013 at 9:4 Comment(0)
S
8

Your p element is already displayed when you enter the text and try to slide it down. So no animation is needed.

$(function () {
  $("#submitBtn").click(function (event) {
    $(".subscribe p").hide().html("Thanks for your interest!").slideDown(4000);
  });
});
Stribling answered 10/7, 2013 at 9:8 Comment(2)
I knew visibility had something to do with it .. Tried other methods to hide it, but didn't work ... Your code works ! Thanks mate ! :DSeismography
You can also hide it on the CSS. Faster that way for the render.Sudoriferous
S
5

You can do it having the content hidden at first and then just showing it with the slideDown function:

HTML

<section class="subscribe">
    <button id="submitBtn" type="submit">Subscribe</button>
    <p>Thanks for your interest!</p>
</section>

CSS

.subscribe p{
    display:none;
}

jQuery

$(function () {
    $("#submitBtn").click(function (event) {
        $(".subscribe p").slideDown({duration: 400});
    });
});

Living example: http://jsfiddle.net/A2mmP/2/

Sudoriferous answered 10/7, 2013 at 9:10 Comment(0)
D
3

Your modified code

$(function () {
    $("#submitBtn").click(function (event) {
        $(".subscribe p").html("Thanks for your interest!").hide().slideDown('400');
    });
});

Check this demo

Differentiation answered 10/7, 2013 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.