最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery animate width to the right - Stack Overflow

programmeradmin0浏览0评论

I want to animate div to slide to the right like the example below:

/

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..

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..

Share Improve this question asked Jan 12, 2013 at 21:10 bushdiverbushdiver 7713 gold badges12 silver badges23 bronze badges 2
  • Please clarify. Preferably with images. a link to fiddle would become useless once it's removed/changed – Matanya Commented Jan 12, 2013 at 21:16
  • Which width do you want to squish? – hugo der hungrige Commented Jan 12, 2013 at 21:18
Add a comment  | 

1 Answer 1

Reset to default 32

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

发布评论

评论列表(0)

  1. 暂无评论