【发布时间】:2016-01-15 07:30:00
【问题描述】:
我有一个 div 动画,可以在指定区域流畅地改变位置。这很好用。 现在我希望动画在鼠标悬停时暂停并在鼠标悬停时恢复,并且在鼠标悬停时放大 div 并在鼠标悬停时调整为以前的小尺寸。
我的代码如下所示:
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 大小的情况下恢复动画,或者在不恢复动画的情况下调整 div 的大小。
有人可以帮我解决这个问题吗?
这是一个有效的 js fiddle
感谢
【问题讨论】:
-
只是告诉你,如果你提供一个像代码 sn-p 或 jsFiddle 这样的工作示例,我敢肯定 SO 上的一些用户会很乐意使用
-
这里我添加了一个暂停插件。那是你要的吗? jsfiddle.net/29cwcx04/3
-
是这样的。但是气泡的大小应该回到以前的较小大小,或者也可以只使用 css 悬停效果?
标签: javascript jquery animation mouseover mouseout