我正在运行时创建一些。为此,我正在使用此功能:
function creatediv(id, html, left, top) {
if (document.getElementById(id))
{
document.getElementById(id).style.display='block';
fadeIn(id, 300);
}
else
{
var newdiv = document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.setAttribute("class", "warningDiv");
newdiv.style.position = "absolute";
newdiv.innerHTML = html + '<h1>(click to close)</h1>';
newdiv.style.left = left;
newdiv.style.top = top;
newdiv.onclick=function(e) {
fadeOutAndHide(id, 300);
};
document.body.appendChild(newdiv);
fadeIn(id, 300);
}
}
此功能不适用于 IE,我不知道为什么。我没有收到这个 javascript 的错误警告。这些是淡入功能:
function fadeOutAndHide (id,millisec)
{
var object = document.getElementById(id).style;
var opacStart = 100;
var opacEnd=0;
var speed = Math.round(millisec / 100);
var timer = 0;
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
var elemento = document.getElementById(id);
if (opacEnd==0){
elemento.style.display='none';
}
}
function opacity(id, opacStart, opacEnd, millisec) {
var speed = Math.round(millisec / 100);
var timer = 0;
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++)
{
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
}
}
我遇到的另一个问题:淡出功能无法正常工作。div 消失,但是当 div 隐藏时触发事件“click”。这是淡出的功能:
function fadeOutAndHide (id,millisec)
{
var object = document.getElementById(id).style;
var opacStart = 100;
var opacEnd=0;
var speed = Math.round(millisec / 100);
var timer = 0;
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
var elemento = document.getElementById(id);
if (i==1){
elemento.style.display='none';
}
}
那么,我能做些什么来解决这个问题呢?
谢谢