2013-08-02 36 views
0

我創造了這個函數來顯示一個彈出和關閉一段時間後:jQuery的VAR和隱藏非常快

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); 

div關閉非常快,並沒有尊重關閉的時間。我使用setTimeout(function()),因爲我需要顯示此div一段時間,然後隱藏2 div。而是在3或4秒內隱藏起來。

+2

時間應是數字,而不是一個字符串。 –

+0

嘗試將int而不是字符串傳入您的'alerta'函數。 'alerta(「40%」,「200px」,「green」,4000,「3000」,「Hello World !!!」)' – zgood

+0

我這樣做,但隱藏時間不尊重 – user2501504

回答

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); 

} 

這裏是演示在MS

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