我正在尝试学习jQuery和弹出窗口。我通过Google找到了这个代码,它很好地工作。 问题是,这个设计只允许通过这个javascript创建一个弹出窗口。我看到作者写道;使用此代码创建多个弹出窗口
如果你想创建多个弹出窗口,而不为每一个你需要创建一个JavaScript对象弹出一个部门,那么你就可以创建弹出对象的多个实例。
更新:下面是我现在使用的代码。我尝试了你的方式,但仍然没有快乐。现在,我无法按照自己的帖子理解的方式创建和弹出窗口。 我回到它的下面,仍然有问题。 Appriciate帮助我。我不明白这是否很难做到这一点。
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: [email protected]
//@license: Feel free to use it, but keep this credits please!
/***************************/
var popupStatus = 0;
function loadPopup()
{
if(popupStatus == 0)
{
$("#backgroundPopup").css({
"opacity": "0.09"
});
$("#backgroundPopup").fadeIn("slow");
$("#myPopup").fadeIn("slow");
popupStatus = 1;
}
}
function disablePopup()
{
if(popupStatus == 1)
{
$("#backgroundPopup").fadeOut("slow");
$("#myPopup").fadeOut("slow");
popupStatus = 0;
}
}
//centering popup
function centerPopup()
{
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#myPopup").height();
var popupWidth = $("#myPopup").width();
$("#myPopup").css({
"position": "absolute",
"top": windowHeight/2 - popupHeight/2,
"left": windowWidth/2 - popupWidth/2
});
$("#backgroundPopup").css({
"height": windowHeight
});
}
$(document).ready(function(){
$("#displaypopup").click(function(){
//centering with css
centerPopup();
//load popup
loadPopup();
});
//CLOSING POPUP
//Click the x event!
$("#popupClose").click(function(){
disablePopup();
});
//Click out event!
$("#backgroundPopup").click(function(){
disablePopup();
});
//Press Escape event!
$(document).keypress(function(e){
if(e.keyCode == 27 && popupStatus == 1){
disablePopup();
}
});
});
感谢尽力帮助我的朋友。我用fancybox js软件包解决了所有问题。保重。 – x0r 2011-12-24 10:55:20