2014-11-09 108 views
-1

我嘗試用jQuery創建滑塊。 這是onLoad事件代碼。如何暫停光標懸停滑塊?

function Slider(){ 
     var delay=5500; 
     var show=2000; 
     var hide=1000; 
     $('#1').show("fade",show); 
     $('#1').delay(delay).hide("fade",{direction:"left"},hide); 
     var n=$('.slider img').size(); 
     var count=2; 
     var t=setInterval(function(){ 
      $('#'+count).show("slide",{direction:"right"},show); 
      $('#'+count).delay(delay).hide("fade",{direction:"left"},hide); 
      if(count==n){ 
       count=1; 
      } 
      else{ 
       count=count+1; 
      } 
     },8000); 
    } 

它的工作,現在,我想暫停它onhover。請幫助我,請。

回答

0

嘗試一些測試。

Slider(false); 

$(".slider img").hover(
    function() { 
    Slider(true); 
    }, function() { 
    Slider(false); 
    } 
); 

function Slider(pause){ 
     if(pause){ 
      return false; 
     } 
     var delay=5500; 
     var show=2000; 
     var hide=1000; 
     $('#1').show("fade",show); 
     $('#1').delay(delay).hide("fade",{direction:"left"},hide); 
     var n=$('.slider img').size(); 
     var count=2; 
     var t=setInterval(function(){ 
      $('#'+count).show("slide",{direction:"right"},show); 
      $('#'+count).delay(delay).hide("fade",{direction:"left"},hide); 
      if(count==n){ 
       count=1; 
      } 
      else{ 
       count=count+1; 
      } 
     },8000); 
    }