【发布时间】:2013-04-23 11:52:39
【问题描述】:
我正在尝试制作一个动画信息气泡(我在这里找到了气泡的 css:http://nicolasgallagher.com/pure-css-speech-bubbles/),每次我的鼠标悬停在链接上时,我都会创建一个 div infoBubble 并且鼠标不在这个 div 我正在使用 .remove() 删除它。但是,当我将鼠标从一个链接快速移动到另一个链接时,.remove() 似乎不适用于第一个 buuble。
我的 jQuery 代码是:
infoBubble = function(el){
setTimeout(function() {
$('body').append('<div class="infoBubble"></div>');
var bubble = $('.infoBubble:last');
var posTop = el.offset().top-el.height()-12;
var posLeft = el.offset().left+el.width()/2-bubble.width()/2;
bubble.css({ 'left':posLeft, 'top':posTop-10, 'background-color': 'rgba(0, 0, 0, 0.7)', 'opacity':1 });
bubble.html('eeeeeeeeee');
bubble.stop().animate({ 'top':posTop },200);
},400);
}
infoBubbleStop = function(){
var bubble = $('.infoBubble:last');
bubble.stop().animate({ 'opacity':0 }, 200, 'linear', function(){ bubble.remove(); });
}
$(document).on('mouseover', 'a', function () {
infoBubble($(this));
}).on('mouseout', function() {
infoBubbleStop();
});
这里有一个小提琴:http://jsfiddle.net/malamine_kebe/YmKT4/
非常感谢您的帮助...
【问题讨论】:
-
无论何时调用 stop() 函数,都不会执行回调。
-
我尝试不使用 stop() 但结果相同
标签: jquery function jquery-animate infobubble