【发布时间】:2013-07-25 09:47:37
【问题描述】:
我正在使用本教程创建翻转墙:http://tutorialzine.com/2010/03/sponsor-wall-flip-jquery-css/
在教程中,翻转元素由 .click 事件触发,我想将其更改为 .mouseover 事件。
我在这里使用 .mouseover 事件设置了一个演示。但是,当您将鼠标悬停在图像上并稍微移动鼠标时,图像会向后翻转。
这是我的 js:
编辑:更新代码
$(document).ready(function(){
var valid = false;
$('.sponsorFlip').bind("mouseenter",function(){
elem = $(this);
if(!valid){
// Using the flip method defined by the plugin:
elem.flip({
direction:'lr',
speed: 250,
onBefore: function(){
// Insert the contents of the .sponsorData div (hidden from view with display:none)
// into the clicked .sponsorFlip div before the flipping animation starts:
elem.html(elem.siblings('.sponsorData').html());
}
});
// Setting the flag:
elem.data('flipped',true);
valid = true;
}
});
$('.sponsorFlip').bind("mouseleave",function(){
elem = $(this);
elem.revertFlip();
valid = false;
});
});
有没有人知道如何在您稍微移动鼠标时防止翻转?我希望元素保持翻转状态,直到鼠标离开该元素。
【问题讨论】:
-
@EvilEpidemic 我现在正在使用 mouseenter,它有效!但是,如果我将鼠标悬停在所有元素上快速停留翻转?
-
你是不是也绑定了 mouseleave 来翻转它们?
-
是的,这是一个小提琴 - jsfiddle.net/csdQB/2