I want to animate div to slide to the right like the example below:
http://jsfiddle.net/56hxy/3/
but instead of shifting the margin, I want to "squish" the width but it's not working by changing the width % ( width: '60%'
) it squishes to the left instead..
jQuery Animations - The animate() Method. The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback); The required params parameter defines the CSS properties to be animated. The optional speed parameter specifies the duration of the effect.
Or give right:0 to #content in the CSS, then you can animate the width and it will shrink from left to right without requiring margins. Same effect as the above but cleaner. Fiddle Also, jQuery has a built-in " toggle event " for alternating clicks so, if you're toggling just the click event you can use:
Remember: The code { width: ‘+=250px’ } tells to increase the element’s width by 250px. If you write multiple .animate () on an element then they will get queue up and will execute one by one.
This will create an animation effect when the div will move to the left side. You can quite easily use the .animate () method on the jQuery Timer example which I created in one of my previous tutorial. We can use any number of CSS properties with the .animate () method.
Not sure if this is exactly what you're looking for but try:
$('#content').animate({
marginLeft: '40%',
width:'60%'
});
Fiddle
Or give right:0
to #content
in the CSS, then you can animate the width
and it will shrink from left to right without requiring margins. Same effect as the above but cleaner. Fiddle
Also, jQuery has a built-in "toggle event" for alternating clicks so, if you're toggling just the click event you can use:
$('#content').toggle(function() {
$(this).animate({ width:'60%' });
}, function() {
$(this).animate({ width:'100%' });
});
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With