我有以下代码,但如果我快速移动鼠标,图像仍会不断淡入和淡出。
如果我使用stop()
, animate()
可以正常工作,但是当我使用此插件时它不会。
$('.person a').live('mouseenter', function() {
$($(this).children('.overstate')).stop().diagonalFade({
time: 350,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'out'
});
}).live('mouseleave', function() {
$($(this).children('.overstate')).stop().diagonalFade({
time: 350,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'in'
});
});
HTML
<div class="person">
<a href="#">
<img src="images/p1h.jpg" />
<span class="name">Lee</span>
<span class="overstate">
<img src="images/p1.jpg" />
</span>
</a>
</div><!--end person-->
CSS
.person { float:left; width:180px; margin-bottom:40px; height:236px; margin-right:31px; }
.lastperson { margin-right:0; }
.person a { display:block; width:180px; height:236px; overflow:hidden; position:relative; }
.person img { position:relative; z-index:2000; }
.name { display:block; width:170px; height:34px; background:url(../images/team-name.png) no-repeat top left; font-size:18px; color:#FFF; text-align:left; line-height:33px; padding-left:10px; float:left; position:relative; z-index:5000;}
.overstate { left:0; top:0; position:absolute; z-index:3000; }
我认为像这样的东西可能会起作用但如果我将鼠标移动几次则会一直闪烁
$('.person a').live('mouseenter', function() {
if (!$(this).children('.overstate').hasClass('animated')) {
$($(this).children('.overstate')).stop().diagonalFade({
time: 450,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'out'
});
}
}).live('mouseleave', function() {
$($(this).children('.overstate')).addClass('animated').stop().diagonalFade({
time: 450,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'in',
complete: function() { $('.person a').children('.overstate').removeClass('animated'); }
});
});
答案 0 :(得分:0)
我担心单一解决方案可能是这样的:
<script>
var inactive = 1;
$(document).ready(function(){
$('.person a').live('mouseenter', function(e) {
if(inactive==1){
inactive = 0;
$($(this).children('.overstate')).stop().diagonalFade({
time: 350,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'out',
complete:function(){
inactive=1;
}
});
}
})
$('.person a').live('mouseleave', function() {
inactive = 0;
$($(this).children('.overstate')).stop().diagonalFade({
time: 350,
fadeDirection_x: 'left-right',
fadeDirection_y: 'top-bottom',
fade: 'in',
complete: function(){
inactive=1;
}
});
});
})
</script>
答案 1 :(得分:0)
jQuery提示:$($(this).children('.overstate')).stop()
是多余的。您只需拨打$(this).children('.overstate').stop()
。