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

javascript - Animate or scale from center - Stack Overflow

programmeradmin1浏览0评论

Any ideas on how to animate the width and height of a div from the top center? Tried using effect('scale') but this is based on a show/hide so snaps back after pletion.

Then tried a normal animate:

$('.box').animate({'width':200px,'height':200px,margin-left:-100px});

This works, but as there is a line of .box, I want the others to react and push to one side.

Any ideas on how to animate the width and height of a div from the top center? Tried using effect('scale') but this is based on a show/hide so snaps back after pletion.

Then tried a normal animate:

$('.box').animate({'width':200px,'height':200px,margin-left:-100px});

This works, but as there is a line of .box, I want the others to react and push to one side.

Share Improve this question edited Nov 14, 2012 at 12:08 Kai 39.7k14 gold badges90 silver badges104 bronze badges asked Nov 14, 2012 at 12:08 TomDTomD 1811 gold badge7 silver badges16 bronze badges 6
  • Its about how this element sits in the page. This isn't flash. – George Commented Nov 14, 2012 at 12:10
  • Use j Query on the others to make it look like it's reacted? – Luke Turnbull Commented Nov 14, 2012 at 12:12
  • 1 Can we see a fiddle? With the HTML and other stuff? – Praveen Kumar Purushothaman Commented Nov 14, 2012 at 12:12
  • Yep fiddle here: jsfiddle/dmYY3 – TomD Commented Nov 14, 2012 at 12:25
  • I've tried adding 'margin-left:-100' on the prev child to pensate but it doesn't seem to solve the issue. (on jsfiddle) – TomD Commented Nov 14, 2012 at 12:57
 |  Show 1 more ment

2 Answers 2

Reset to default 3

Fine Tuned

FIDDLE

$('.day').hover(function() {

  if($(this).index()==0){
      $(this).animate({'width':400,'height':400}, 500);
  }else{            
      $(this).animate({'width':400,'height':400}, 500);
      $(this).parent().stop().animate({'margin-left':'-100'} , 500);  
  }          
}, function() {
   $(this).animate({'width':200,'height':200}, 500);
   $(this).parent().stop().animate({'margin-left':'0'}, 500);

});

Maybe like this:

$('.day').hover(function() {
    $(this).animate({'width':400,'height':400, 'margin':'-100px -90px'});        
}, function() {
    $(this).animate({'width':200,'height':200, 'margin': '0 10px'});      
});

Fiddle: http://jsfiddle/dmYY3/3/ ?

发布评论

评论列表(0)

  1. 暂无评论