2014-01-21 38 views
0

我在javascript和css中做了一個旋轉滑塊。 Javascript功能使其旋轉。當我第一次加載頁面時,它工作正常,但當我導航到其他頁面,然後返回時,js函數被調用,但滑塊不停止旋轉鼠標懸停。我做了一個js函數,當鼠標懸停DIV的旋轉停止,當它離開該功能被稱爲again.Here是我的js代碼爲什麼javascript函數在返回後停止工作?

var timer; 
     window.onload = function() 
     { 
      myTimer(); 
     }; 

var $i=1; 
function myTimer(){ 
       timer=setInterval(function(){ 
        if($i<6){ 
         closeTab(); 
         openTab($i); 
         $i++; 
        } 
        else 
        {$i=1;} 
       },2000); 
      } 
closeTab(); 

      var selectedSlider ; 
      function closeTab() 
      { 
       var $this = $('#accordion > li'); 
       //$width=$(window).width(); 
       //$this.stop().animate({'width':'110px'},500); 
       $this.stop().animate({'width':'7%'},500); 
       $('.heading',$this).stop(true,true).fadeIn(); 
       $('.description',$this).stop(true,true).fadeOut(500); 
       $('.bgDescription',$this).stop(true,true).slideUp(700); 
      } 
      function openTab(id) 
      { 
       var $this = $('.bg'+id);           
       //$this.stop().animate({'width':'450px'},500); 
       $this.stop().animate({'width':'70%'},500); 
       $('.heading',$this).stop(true,true).fadeOut(); 
       $('.bgDescription',$this).stop(true,true).slideDown(500); 
       $('.description',$this).stop(true,true).fadeIn(); 
      } 

openTab(1); 
      $(function() { 
       $('#accordion > li').hover(
       function() { 
        console.log("in mouse hover"); 
        var $this = $(this); 
        selectedSlider = $this.attr("class").replace("bg", ""); 
        closeTab(); 
        openTab(selectedSlider); 
        clearInterval(timer); 
       }, 

       function() { 

       } 
      ); 
      }); 
$('#accordion > li').mouseleave(function(){ 
       console.log("in mouse leave"); 
       myTimer(); 
      }); 
+0

這樣的事發生在我身上,因爲瀏覽器正在緩存javascript(錯誤的方式)。 –

+0

大衛你實現了什麼解決方案來解決這個問題? –

+0

我在Apache服務器上的.htaccess文件中更改了緩存設置。 @jailedabroad –

回答

0

正如@大衛說,瀏覽器被緩存的JavaScript,因此您的代碼懸停效果是不行的,因爲你把它放在這樣一個方式,當js文件將調用懸停事件是火,但在這裏js文件已被緩存。

你可以試試這個,而不是使用懸停功能匿名放在window.onload裏面。

+0

同樣的結果...... –

+0

在實施更改之前是否清除了瀏覽器緩存? –

+0

是的,我有............. –

相關問題