【发布时间】:2012-11-12 22:47:24
【问题描述】:
我猜setTimeout() 有问题。
您可以访问我的网页以查看我的位置:http://verbum.xtrweb/soon.php
问题是我有 2 个文本字段。
- “动词”与
id="Verbum" - 使用
id="forget"“忘记单次搜索”
我想在小字典掉落后应用淡入效果(请参阅上面的我的网站链接,以便您理解)。我也更改了函数的名称和变量,但唯一发生的事情是只有一个文本淡入,这取决于一个在另一个之下的顺序。不淡入的那个甚至都没有出现。希望你能理解并找到答案。谢谢。
<script type="text/javascript">
var opac = 0.0;
var alpha = 0;
function init() {
var elem = document.getElementById("Verbum");
elem.style.display = 'inline';
elem.style.filter = "alpha(opacity = " + alpha + ")";
elem.style.opacity = opac;
setTimeout("fadein()", 8500);
}
function fadein() {
var elem = document.getElementById("Verbum");
opac = opac + 0.1;
alpha = parseInt(opac * 100);
elem.style.opacity = opac;
elem.style.filter = "alpha(opacity = " + alpha + ")";
if (opac < 1.0) {
//Change the 50 to adjust the speed. The higher the number, the slower the fade
setTimeout("fadein()", 30);
}
}
window.onload=init;
</script>
这是第二个<script> 块:
<script type="text/javascript">
var opac = 0.0;
var alpha = 0;
function init() {
var eleme = document.getElementById("forget");
eleme.style.display = 'inline';
eleme.style.filter = "alpha(opacity = " + alpha + ")";
eleme.style.opacity = opac;
setTimeout("fadein()", 7500);
}
function fadein() {
var eleme = document.getElementById("forget");
opac = opac + 0.1;
alpha = parseInt(opac * 100);
eleme.style.opacity = opac;
eleme.style.filter = "alpha(opacity = " + alpha + ")";
if (opac < 1.0) {
// Change the 50 to adjust the speed. The higher the number, the slower the fade
setTimeout("fadein()", 30);
}
}
window.onload = init;
</script>
【问题讨论】:
-
快速说明:易于阅读的代码更有可能促进解决方案。请注意对缩进和间距所做的特定更改,因为它们大大提高了代码的可读性。此外,这只是一个猜测,但您不能以这种方式设置两个
onload函数。将它们组合成一个初始化函数。 -
您的网站链接无效?
-
完全正确。它的:verbum.xtrweb.com
标签: html css settimeout