2015-10-16 67 views
3

我有一个动态的div来在指定区域流畅地改变位置。这很好地工作。 现在我想动画暂停鼠标悬停并恢复鼠标加上有鼠标悬停的div放大和调整大小以前的小型鼠标。jquery .animate()mouseover/mousout

我的代码如下所示:

function animateBubble(canvas, bubble){ 

    newB = newSize(); 
    newQ = newPosition(canvas, bubble); 
    oldQ = $(bubble).offset(); 
    speed = calcSpeed([oldQ.top, oldQ.left], newQ); 

    $(bubble).animate({ // initial animation start of bubble 
     top: newQ[0], 
     left: newQ[1], 
     width: newB[0], 
     height: newB[1] 
    }, 
    { duration: speed, // set the duration 
     step: function(now, fx) { // get the coordinates of the bubble dynamically 
      var offset = $(this).offset(); 
      xPos = offset.left; // now position 
      yPos = offset.top; 
      nowWidth = $(this).width(); 
      nowHeight = $(this).height(); 
     }, 
     complete: function(){ // do the whole animation again upon completion 
      animateBubble(canvas, bubble); 
     } 
    }).mouseover(function(){ // pause animation on mouseover 
     $(bubble).stop(); 
     $(bubble).height(230); 
     $(bubble).width(230); 
     }).mouseleave(function(){ // restart animation on mouseout 
      //alert('hello'); 
      $(this).height(nowHeight); 
      $(this).width(nowWidth); 
      $(this).start(); 
      animateBubble(canvas, bubble); // doesn't want to start again 
     }); 
} 

看来,鼠标移开时我可以恢复动画不调整股利,或调整DIV而不恢复动画。

有人可以帮我这个吗?

这里是工作的js小提琴

http://jsfiddle.net/29cwcx04/

感谢名单

+2

只是告诉你,如果你提供像代码片段或的jsfiddle工作示例,我确信这里的一些用户,这样将非常高兴与刚刚添加 –

+0

玩jsfiddle – Chris

+0

这里我添加了一个暂停插件。那是你要的吗? http://jsfiddle.net/29cwcx04/3/ – AtheistP3ace

回答

1

的问题,我认为,这是你的切割前的宽度和高度动画公司做重新调整大小的圆圈回正常尺寸。这里'山快速修复:

...mouseleave(function(){ // restart animation on mouseout 
      //alert('hello'); 
      $(this).height(nowHeight); 
      $(this).width(nowWidth); 
      setTimeout(function(){animateBubble(canvas, bubble);},1000); 
     }); 
+1

是的,谢谢你的修复 它的工作 我曾尝试过,但我认为我有一个语法错误。 Thanx – Chris