0
嘿,我在這裏搜索過,但找不到答案。經過一定時間後自動關閉模式框
我有一個Joomla網站,並希望在頁面加載時使用模式框在網站中間顯示橫幅。到目前爲止,我使用這個腳本我發現這裏:http://www.thesimplexdesign.com/2011/03/update-for-subscription-pop-up.html和一切工作像一個魅力。
我的問題是,當我添加自己的代碼,自動關閉模式框。此代碼有效,但用戶無法自行關閉模式。你能指導我做什麼,因爲它應該(它可以自動關閉,但也可以由用戶關閉)?
我的代碼是一個與評論//延遲後淡出
CODE:
var popupStatus = 0;
var $j = jQuery.noConflict();
//this code will load popup with jQuery magic!
function loadPopup(){
//loads popup only if it is disabled
if(popupStatus==0){
$j("#backgroundPopup").css({
"opacity": "0.7"
});
$j("#backgroundPopup").fadeIn("slow");
$j("#popupContact").fadeIn("slow");
popupStatus = 1;
}
}
//This code will disable popup when click on x!
function disablePopup(){
//disables popup only if it is enabled
if(popupStatus==1){
$j("#backgroundPopup").fadeOut("slow");
$j("#popupContact").fadeOut("slow");
popupStatus = 0;
}
}
//this code will center popup
function centerPopup(){
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $j("#popupContact").height();
var popupWidth = $j("#popupContact").width();
//centering
$j("#popupContact").css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/2
});
//only need force for IE6
$j("#backgroundPopup").css({
"height": windowHeight
});
}
//CONTROLLING EVENTS IN jQuery
$j(document).ready(function(){
if ($j.cookie("anewsletter") != 1) {
//centering with css
centerPopup();
//load popup
loadPopup();
$j.cookie("anewsletter", "1", { expires: 1 });
}
//CLOSING POPUP
//Click the x event!
$j("#popupContactClose").click(function(){
disablePopup();
});
//Click out event!
$j("#backgroundPopup").click(function(){
disablePopup();
});
//Press Escape event!
$j(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
}
});
//fade out after delay
$j("#backgroundPopup").delay(15000).fadeOut("slow");
$j("#popupContact").delay(15000).fadeOut("slow");
});
你有沒有嘗試過使用'setTimeout()'? – dunli 2013-04-04 09:35:06
哇,做到了!非常感謝!!! – Panos 2013-04-04 09:38:49
沒問題,我應該發表一個答案嗎? :D – dunli 2013-04-04 09:40:10