我有這個js函數:回調.hover功能心不是工作
$('#linkNext').on({
mouseenter: function() {
if ($('#conteudo .boxes').hasClass('ativo')) {
$('#conteudo .boxes').removeClass('ativo');
$('.boxAberto').animate({width: '0'}, 600, function() {
// callback
$('#linkNext').hover(function() {
this.iid = setInterval(function() {
if (cont > -565) {
cont -= 5;
$('#conteudo').attr('style', 'left:' + cont + 'px');
console.log(cont)
}
if (cont <= -565) {
$('#linkNext').hide();
}
}, 0);
});
$('#linkNext').mouseleave(function() {
this.iid && clearInterval(this.iid);
});
// callback ends
});
} else {
this.iid = setInterval(function() {
if (cont > -565) {
cont -= 5;
$('#conteudo').attr('style', 'left:' + cont + 'px');
console.log(cont)
}
if (cont <= -565) {
$('#linkNext').hide();
}
}, 0);
}
},
mouseleave: function() {
this.iid && clearInterval(this.iid);
}
});
鼠標懸停時,它會檢查元素具有類.ativo
。如果有,它將刪除該類併爲元素設置動畫,並調用回調。回調沒有工作,我想即時用錯誤的方式使用.hover
。
在else
它將開始setInterval
這是工作很好,mouseleave
功能也是如此。我的問題是唯一的回調,我不知道我在做什麼錯
* 編輯 **
現在我改變了代碼,只使用.hover
有回調,而不是使用.on
與mouseenter mouseleave
。但我仍然有同樣的問題。行// callback
心不是工作上面的回調..
$('#linkNext').hover(function() {
if ($('#conteudo .boxes').hasClass('ativo')) {
$('#conteudo .boxes').removeClass('ativo');
$('.boxAberto').animate({width: '0'}, 600, function() {
// callback
if ($('#conteudo .boxes:not(.ativo)')) {
$('#linkNext').hover(function() {
this.iid = setInterval(function() {
if (cont > -565) {
cont -= 5;
$('#conteudo').attr('style', 'left:' + cont + 'px');
console.log(cont)
}
if (cont <= -565) {
$('#linkNext').hide();
}
}, 0);
}, function() {
this.iid && clearInterval(this.iid);
});
}
});
} else {
this.iid = setInterval(function() {
if (cont > -565) {
cont -= 5;
$('#conteudo').attr('style', 'left:' + cont + 'px');
console.log(cont)
}
if (cont <= -565) {
$('#linkNext').hide();
}
}, 0);
}
}, function() {
this.iid && clearInterval(this.iid);
});
你用什麼版本的jQuery? – PlantTheIdea 2013-04-08 21:53:28
即時通訊使用v1.8.3 – 2013-04-08 21:54:30
爲什麼在鼠標輸入功能中設置懸停功能和鼠標離開功能? – Ohgodwhy 2013-04-08 21:58:24