0

I have created one menu using div animating in the middle i have structured. present when i clicked on open button that div menu is expending to right side some fixed width. but my requirement is after expanded the menu instead of open "close" word need to append. when click on "close" div menu should collapse to previous width and "open" will come instead of close.

0

1 Answer 1

1

The animate function has a complete parameter where you can provide a callback. http://api.jquery.com/animate/

This callback will be triggered after the event completes. In this callback you can edit your values.

Change the class of your li to 'close'. Also: use the 'live' binding. This one will work even with dynamic changing html.

CSS:

.open{
    cursor:pointer;
    background:black;
    color:white;
}
.close {
    cursor:pointer;
    background:black;
    color:white; 
}

JS:

$(".open").live('click', function() {
$("#navMenu").animate({
    width: "82px"
}, {
    queue: false,
    duration: 500,
    complete: function() {
        $(".open").text("<- CLOSE");
        var $this = $(".open");
        $this.removeClass();
        $this.addClass("close");
    }
});
});

$(".close ").live('click', function() {
$("#navMenu ").animate({
        width: "50px"
    }, {
        queue: false,
        duration: 500,
        complete: function() {
            $(".close").text("OPEN - >");
            var $this = $(".close");
            $this.removeClass();
            $this.addClass("open");
        }
    });
});​
Sign up to request clarification or add additional context in comments.

4 Comments

First of all thanks for your answer but just i placed with my code which i placed in my fiddle but it's not working.
I wrote it just out of thin air. I updated my code. Tested in your fiddle :)
thank you... close text is coming but after clicked on close again it should go to Open.... hope you can understand
of course I do. As you can see, the animate function will animate the windows to 84px. As it already is 84px, you won't see anything. My suggestion is to create another click event for $(".close").click() and change your class of your li to "close".

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.