我在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();
});
這樣的事發生在我身上,因爲瀏覽器正在緩存javascript(錯誤的方式)。 –
大衛你實現了什麼解決方案來解決這個問題? –
我在Apache服務器上的.htaccess文件中更改了緩存設置。 @jailedabroad –