【发布时间】:2013-08-09 21:27:57
【问题描述】:
当我的鼠标悬停在 div .test 上时,我希望 div .box 使用 slideToggle 高于 .test,当鼠标离开 .test 时,我希望 .box 再次使用 slideToggle。
它运行良好,但是当我在 .test 的左上角移动鼠标时,它似乎不起作用,我不知道为什么......
我的 CSS 是:
.box{
z-index:2;
position: absolute;
}
还有我的 jQuery:
box = function(el) {
$('body').append('<div class="box"></div>');
var box = $('.box:last');
var posTop = el.offset().top;
var posLeft = el.offset().left;
box.hide().css({
'left': posLeft,
'top': posTop
}).html('azerty<br>azerty<br>azerty<br>azerty<br>azerty<br>azerty<br>azerty').slideToggle(150);
}
boxStop = function() {
var box = $('.box:last');
box.stop().slideToggle(150, function() {box.remove();});
}
$(document).on('mouseover', '.test', function() {
box($(this));
}).on('mouseout', function() {
boxStop();
});
【问题讨论】:
-
是因为向下滑动的元素突然出现在你的鼠标指针所在的位置,触发了原元素的mouseleave事件,又向上滑动,常见错误。
标签: jquery function slidetoggle