該代碼在Chrome中運行完美,但Firefox說功能tile1
未定義。可能是什麼問題呢?功能在Chrome中運行,但不在Firefox中運行說功能未定義
另外,有沒有什麼辦法縮短這個功能?我曾嘗試在tile1
以及if-else
聲明中使用for循環,但我沒有成功。
$('div.tile').each(function(index, element) {
for(var i=0;i<=index;i++){
var tile1=function(){
var one ="div.tile div.one";
var two =" div.tile div.two";
var three = "div.tile div.three";
if(index==0){
one="div.tile div.one";
two="div.tile div.two";
three="div.tile div.three";
} else {
one ="div.tile div.one"+index;
two ="div.tile div.two"+index;
three ="div.tile div.three"+index;
}
var $one=$(one);
var $two = $(two);
var $three=$(three);
var oneTop = $one.top;
var twoTop = $two.top;
var threeTop = $three.top;
delayRate += 3000; // delayRate 5 sec (5000) by default
$one
.delay(delayRate)
.animate({top: "-100.5%"},300,easing);
$two
.delay(delayRate)
.animate({top:"0%"},300,easing);
$three
.delay(delayRate)
.animate({top:"100.5%"},300,easing);
$one
.delay(12000)
.animate({top: "-200.5%"},300,easing);
$two
.delay(12000)
.animate({top:"-100.5%"},300,easing);
$three
.delay(12000)
.animate({top:"0"},300,easing);
$one
.delay(12000)
.animate({top: "-100.5%"},300,easing);
$two
.delay(12000)
.animate({top:"0"},300,easing);
$three
.delay(12000)
.animate({top:"100.5%"},300,easing);
$one
.delay(15000-delayRate)
.animate({top: "0"},300,easing);
$two
.delay(15000-delayRate)
.animate({top:"100.5%"},300,easing);
$three
.delay(15000-delayRate)
.animate({top:"200.5%"},300,easing);
if(i==3){
delayRate=0;
}
}
}
window.setInterval(tile1, 3000);
});
正如我調用該函數的index
自帶隨機像0,3,1,2,和有該索引對應於4個格。
wat是'.top'? –
其實你是否可以澄清你是想創建一大堆函數還是隻是一個'tile1'?謝謝。如果你只想要一個,那麼你希望它具有的「我」的價值是多少? –
可能重複的[Javascript功能無法找到](http://stackoverflow.com/questions/15573202/javascript-function-cannot-be-found) – Bergi