0

Having a spot of bother with the following code. Essentially I have a div container that is height:40px, when I click on it, it smoothly grows to 320px - this works great, however when the div has grown to full height, I then want the overflow property to change from it's static state of hidden, to visible.

$(document).ready(function() {
    $('#join').click(function() {
        $('#join').animate({ height: "320px" }, 500);
        $('#join').css('overflow', 'visible');
    })
});​

It does go visible for a few seconds but then disappears, also I want it to happen after the div has grown to full height.

2 Answers 2

4

Apply the style inside the animate callback function.. See below,

$(this).animate({height:"320px"}, 500, function () { //this <- #join
   $(this).css('overflow', 'visible');
});

Complete code:

$(document).ready(function() {
   $('#join').click(function() {
       $(this).animate({height:"320px"}, 500, function () {
            $(this).css('overflow', 'visible');
       });
   });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Note that, the first DOM query can be avoid as well.
@PeteNorris. Family hug... :)
3

Then pass it as a callback:

$(this).animate({height:"320px"}, 500, function(){
    $(this).css('overflow', 'visible')
});

Full code:

$(document).ready(function() {
    $('#join').click(function() {
        $(this).animate({
            height: "320px"
        }, 500, function() {
            $(this).css('overflow', 'visible');
        });
    });
});​

2 Comments

Typo :P {); in $(this).animate({height:"320px"}, 500, function(){);
@Vega. You meant "by whole 3 seconds!" :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.