Wednesday, October 8, 2014

Expand and shrink animate on click jquery

This short jquery script makes an element shrink or expand on click. Simple logic is added to make the script toggle on click.
$(document).ready(function() {     
    var move = "expand";
    $('div').click(function(){
            if (move == "expand"){
                $('div').animate({width:"30px",height:"30px"},500);
                move = "shrink";
            } else {
                $('div').animate({width:"80px",height:"80px"},500); 
                move = "expand";
            }
    });  
});
Live Demo

No comments:

Post a Comment