您在<代码>fadeIn()职能方面遇到若干问题:
A. 导 言 您的住宿条件是i=100
,这在第一次停业时并不真实,因此, lo体永远不会被执行(i++>
胜过)。 也许你指的是<代码>i<=100或i<100
(取决于你是否希望该休息时间为101或100倍)?
www.un.org/Depts/DGACM/index_chinese.htm 因此,你要么通过“无<>括号/>的职能名称,要么通过匿名功能表达,在我下面的法典中可以看到。 <>在你试图建造你通过座椅时。 页: 1
"Opacityto("+elem,i+")"
但需要:
"Opacityto(elem," + i + ")"
后者产生一种说明,即视<代码>i,即“Opacityto(elem,0)”
,即产生有效的 Java本,称为。
C. You probably want setTimeout()
rather than setInterval()
, because setInterval()
will run your Opacityto()
function every 100ms forever, while setTimeout()
will run Opacityto()
exactly once after the 100ms delay. Given that you are calling it in a loop I m sure you don t really want to call setInterval()
100 times to cause your function Opacityto()
to be run 100 times every 100ms forever.
D. 出席情况 即便是确定上述所有内容,你的基本结构也不会做你想要的。 当你打电话setInterval(
或settimeout(
)时,不暂停执行现行代码。 因此,整个休息室将一劳永逸地运行和创造你的所有间隔/时间,然后当100米左右时,就会一劳永逸地引发。 如果你的意图是逐步改变每百位人每次变化的不透明性,那么你需要以下法典(或其中某些改动):
function fadeIn(i){
// if called with no i parameter value initialise i
if (typeof i === "undefined") {
i = -1;
}
if (++i <= 100) {
Opacityto(document.getElementById( nav ), i);
setTimeout(function() { fadeIn(i); }, 100);
}
}
// kick it off:
fadeIn();
What the above does is defines fadeIn()
and then calls it passing no parameter. The function checks if i
is undefined and if so sets it to -1 (which is what happens if you call it without passing a parameter). Then it increments i
and checks if the result is less than or equal to 100 and if so calls Opacityto()
passing a reference to the element and i
. Then it uses setTimeout()
to call itself in 100ms time, passing the current i
through. Because the setTimeout()
is inside the if test, once i
gets big enough the function stops setting timeouts and the whole process ends.
你可以采取其他几种办法,但这只是我开始打字时的第一次。