English 中文(简体)
js fade inLoad with for-loop, Format and set 间隔时间没有工作?
原标题:js fade in onLoad with for-loop, styles, and setInterval not working?

为什么在Load打电话时,浏览器会立即穿透。 换言之,既有间隔期,也有间隔期。

function Opacityto(elem,v){
    elem.style.opacity = v/100;
    elem.style.MozOpacity =  v/100;
    elem.style.KhtmlOpacity =  v/100;
    elem.style.filter=" alpha(opacity ="+v+")";}

function fadeIn(){
elem=document.getElementById( nav );
for (i=0;i==100;i++){
    setInterval(Opacityto(elem,i),100);}
}

我认为,有人会告诉我,这可以最容易地用 j子做,但我很有兴趣用 j子做。

感谢! HelP!

最佳回答

您在<代码>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.

你可以采取其他几种办法,但这只是我开始打字时的第一次。

问题回答

我的猜测是,在规定的 set内有nas子。 相互之间,说明理由清单:

"Opacityto("+elem,i+")"
                ^^^
                here

你可以尝试引用 com子

+ "," + 

但是,邪恶却不然。 良好的办法是通过真正的反馈功能:

function make_opacity_setter(elem, i){
    return function(){
        OpacityTo(elem, i);
    };
}

...

setTimeout( make_opacity_setter(elem, i), 1000);

请注意,为了避免关闭和排行之间的新互动,需要中间功能-创造功能。


BTW, 当你做时

setInterval(func(), 1000)

页: 1 围产期从那时起,它得到的是一种珍贵的价值,而不是像你所希望的那样赢得的 t。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.