2012-11-28 58 views
4

我創建了一個編輯simple.carousel.js停止旋轉木馬時,但我有一個問題時重新啓動它,當mouseleave。我加入simple.carousel.js的代碼是:mouseenter mouseleave jquery懸停並重新啓動與simple.carousel.js問題

// hover stop 
if(config.auto!=true) 
    $(this).mouseenter(function() { 
     config.auto=false; 
    }).mouseleave(function() { 
     config.auto=true; 
    }); 

你可以在這裏與我的另外從上面看到完整的代碼/例如:http://jsfiddle.net/6r6sC/2/

是什麼毛病我的鼠標離開功能?

不知道這是否會幫助,但我也試着以下但不工作,要麼:

// hover stop 
if(config.auto!=true) 
    $(this).mouseenter(function() { 
     config.auto=false; 
    }).mouseleave(function() { 
     setTimeout(function() { 
     slide('next'); 
    }, config.auto); 
    }); 

任何幫助將不勝感激,因爲這有我難住了。

+0

有了第一個代碼,加載PAG汽車時只發揮了作用。 – InfiniDaZa

回答

-1

好吧,我已經做了一些研究和測試,並將'mouseleave'替換爲'mouseout'它的工作原理!所以試試看。

// hover stop 
if(config.auto!=true) 
$(this).mouseenter(function() { 
    config.auto=false; 
}).mouseout(function() { 
    config.auto=true; 
}); 
+0

反對,對mouseout不起作用,滑塊以0ms間隔旋轉=> http://jsfiddle.net/6r6sC/13/ – anderssonola

+0

雅,我之前嘗試過,不起作用。不過謝謝。 – jgrannis

0

使用true作爲一個值是一個問題,導致false布爾值或從你的init函數中得到一個int值。

EDIT 4: http://jsfiddle.net/6r6sC/44/

在滑動

()中,加入startAuto()

if(config.auto!=false) { 
startAuto();  
} 

EDIT3: 修正了多個定時器的問題,並且創建了兩個函數來處理啓動/停止自動滑塊。

這裏的解決方案:http://jsfiddle.net/6r6sC/41/

var cachedAuto = config.auto; 
var timer = ""; 

var startAuto = function() { 

    config.auto = cachedAuto; 
    clearTimeout(timer); 

    timer = setTimeout(function() { 
     slide('next'); 
    }, config.auto); 
} 

var stopAuto = function() { 
    clearTimeout(timer); 
    config.auto = false; 
} 

if(config.auto!=false) { 
    // start auto sliding 
    startAuto();  

    // pause/start on mouse events    
    $(this).on("mouseenter", function(event){ 
     stopAuto(); 
    }).on("mouseleave", function(event){ 
     startAuto(); 
    }); 
} 
+0

嗯,似乎運作良好,但一旦你開始移動你的鼠標進出,讓它重新啓動它開始有點瘋狂(和快速)。你明白我的意思嗎? – jgrannis

+0

不好意思更新了jsfiddle,超時被觸發了兩次。 http://jsfiddle.net/6r6sC/15/ – anderssonola

+0

對不起,哪部分更新? setTimeout的?代碼對我來說看起來是一樣的。感謝你的幫助。 – jgrannis