我認爲問題是,當你將鼠標移動到觸發其隱藏的加號圖標,這反過來又觸發project-thumbnail
鼠標再次輸入處理您的project-thumbnail
鼠標離開處理程序中的加號圖標它顯示加號圖標 - 但是你的鼠標已經超過加號,所以再次觸發鼠標離開處理程序等等等等。當然,口吃是因爲動畫開始和反覆停止。
也許你可以修改你的HTML結構把project-thumbnail
DIV中的加鏈接 - bondythegreat的有你覆蓋那裏。
或者你可以嘗試這樣的黑客:
var projectThumbnail = $('.project-thumbnail'),
imgWidth = projectThumbnail.width(),
imgHeight = projectThumbnail.height(),
timeoutID; // <-- new variable
projectThumbnail.mouseenter(function(e) {
$(this).children('a').children('img').stop().animate({ height: imgHeight, left: '0', top: '0', width: imgWidth}, 100);
$(this).children('a').children('span').stop().fadeIn(200);
$(this).next('.zoom-button').show();
}).mouseleave(function(e) {
// move original functionality into a timeout, saving a reference
// to this for use within the timeout
var $this = $(this);
timeoutID = setTimeout(function() {
$this.children('a').children('img').stop().animate({ height: imgHeight + 33, left: '-20', top: '-20', width: imgWidth + 50}, 100);
$this.children('a').children('span').stop().fadeOut(200);
$this.next('.zoom-button').hide();
}, 5);
});
// cancel the timeout when entering the plus button
$(".zoom-button").mouseenter(function(e) {
clearTimeout(timeoutID);
});
演示:http://jsfiddle.net/NrtvK/2/
(我知道這是很狡猾的,但我想它的好奇心,當它的工作我想我可能以及它張貼)
謝謝佐爾坦。我喜歡這個jQuery解決方案。 – mousesports
不客氣 –