0

我创建了这个函数来显示一个弹出窗口并在一段时间后关闭:

function alerta(ancho,alto,color,tiempo_s,tiempo,contenido) {
    $("#alert_background").show();
    $("#alert_window").show(1000);
    $("#alert_window").css("width",""+ancho);
    $("#alert_window").css("height",""+alto);
    $("#alert_window").css("background-color",""+color);
    $("#alert_window").append(""+contenido);

    if(tiempo!="") {
        setTimeout(function() {
            $("#alert_background").hide(tiempo);
            $("#alert_window").hide(tiempo);
        }, tiempo_s);
    }
}

alerta("40%","200px","green","4000","3000","<b>Hello World!!!</b>")

我唯一的问题是在这个函数中:

$("#alert_background").hide(tiempo);
$("#alert_window").hide(tiempo);

s 关闭非常快,div不尊重关闭时间。我使用setTimeout(function())是因为我需要显示这个 div 一段时间,然后隐藏 2 divs。相反,divs 会在 3 或 4 秒内隐藏。

4

1 回答 1

0

试试看

function alerta(ancho,alto,color,timeOut,durationFadeOut,content) {
    $("#alert_background").fadeIn(1000);
    $("#alert_window").fadeIn(1000);
    $("#alert_window").css("width",ancho);
    $("#alert_window").css("height",alto);
    $("#alert_window").css("background-color",color);
    $("#alert_window").html(content);

    setTimeout(function(){
               $("#alert_background").fadeOut(durationFadeOut);
                $("#alert_window").fadeOut(durationFadeOut);
            }, timeOut);

}

这是演示

http://jsfiddle.net/5XQkY/32/

于 2013-08-02T20:09:09.527 回答