Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Animating Div Resize on 'Click'

I have a div I'm using to show the user a status. Its width is relative to the percentage (0-100). Upon click of a button, I'd like to animate the width (in pixels) of that div. Any input on the best way to go about this? I'm already using jQuery, I assume it will use that to animate? (My panel is initially hidden, hence the .live function).

$('#slider50').live("click", function() {

   // Animate here

    });
like image 914
Zakman411 Avatar asked Sep 04 '11 01:09

Zakman411


2 Answers

As stated by PeeHaa you can use the .animate() jQuery function to expand you're div's width as shown in the example below:

http://jsfiddle.net/DKjKP/1/

$("#button").click(function() {
    $("#slider").animate({
        width: '+=30px'
    }, 1000);
});
like image 189
Bassem Avatar answered Oct 12 '22 22:10

Bassem


An easy solution that I think would work would be some something similar to this:

$("#slider50").live("click", function() {
  $(this).slideDown();

  /*  or something like this
    $(this).animate({
      'width' : '500px',
      'height': '500px' 
    });
  */
 });

Hope this helps

like image 42
GoGoGarrett Avatar answered Oct 13 '22 00:10

GoGoGarrett