该代码在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