Thursday, April 21, 2011

Animate width left to right

I am trying to find a way to animate a div using jQuery to shrink the width from left to right.

I have the element on click at first:

  • slide in from left to right
  • then have it continue to the right off my div, like it just keeps moving off the page, comes in and click again comes off. I have the toggle function in and working properly, but I am not sure how to make it keep moving off the page.

Any ideas?

THanks,

Ryan

From stackoverflow
  • Shrink it right to left (like you know how to), but simultaneously increase the left position style, or the left margin.

    Something like:

    var distance = $("div").css("width");
    
    $("div").animate({
    "width": "0",
    "marginLeft": distance
    });
    
    Coughlin : Will this work even if im using the image as a background image?
  • you need to set the margin property. But you'll also want to position it absolutely if there's any elements either side of it.

    Coughlin : Ended up working with something like this. Appreciate this. Thank you.

0 comments:

Post a Comment