可自己添加html的偽彈出框?qū)崿F(xiàn)代碼
更新時間:2013年09月08日 16:18:46 作者:
本文為大家介紹下html偽彈出框的實現(xiàn),感興趣的朋友可以了解下
js
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup(){
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow");
popupStatus = 1;
}
}
//disabling popup with jQuery magic!
function disablePopup(){
//disables popup only if it is enabled
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
}
}
//centering popup
function centerPopup(){
//request data for centering
var browser=navigator.userAgent;
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var stop="";
var sleft="";
if(browser.indexOf('Chrome')!=-1){
stop=document.body.scrollTop;
sleft=document.body.scrollLeft;
}
else{
stop=document.documentElement.scrollTop;
sleft=document.documentElement.scrollLeft;
}
// windowWidth+=document.body.scrollLeft;
// windowHeight+=document.body.scrollTop;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
$("#popupContact").css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2+stop,
"left": windowWidth/2-popupWidth/2+sleft
});
//only need force for IE6
//背景色
$("#backgroundPopup").css({
"height": windowHeight
});
}
//調(diào)用彈出框事件
function bb(str){
$("#download").show();
centerPopup();
loadPopup();
//CLOSING POPUP
//Click the x event!
$("#popupContactClose").click(function(){
disablePopup();
});
//Click out event!,點擊背景事件
$("#backgroundPopup").click(function(){
disablePopup();
});
//Press Escape event!
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
}
});
}
html代碼(默認(rèn)隱藏)
<div id="download" style="display: none;">
<div id="popupContact">
<!--自己的 HTML(body中)-->
</div>
<div id="backgroundPopup"></div>
</div>
</div>
復(fù)制代碼 代碼如下:
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup(){
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow");
popupStatus = 1;
}
}
//disabling popup with jQuery magic!
function disablePopup(){
//disables popup only if it is enabled
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
}
}
//centering popup
function centerPopup(){
//request data for centering
var browser=navigator.userAgent;
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var stop="";
var sleft="";
if(browser.indexOf('Chrome')!=-1){
stop=document.body.scrollTop;
sleft=document.body.scrollLeft;
}
else{
stop=document.documentElement.scrollTop;
sleft=document.documentElement.scrollLeft;
}
// windowWidth+=document.body.scrollLeft;
// windowHeight+=document.body.scrollTop;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
$("#popupContact").css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2+stop,
"left": windowWidth/2-popupWidth/2+sleft
});
//only need force for IE6
//背景色
$("#backgroundPopup").css({
"height": windowHeight
});
}
//調(diào)用彈出框事件
function bb(str){
$("#download").show();
centerPopup();
loadPopup();
//CLOSING POPUP
//Click the x event!
$("#popupContactClose").click(function(){
disablePopup();
});
//Click out event!,點擊背景事件
$("#backgroundPopup").click(function(){
disablePopup();
});
//Press Escape event!
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
}
});
}
html代碼(默認(rèn)隱藏)
復(fù)制代碼 代碼如下:
<div id="download" style="display: none;">
<div id="popupContact">
<!--自己的 HTML(body中)-->
</div>
<div id="backgroundPopup"></div>
</div>
</div>
相關(guān)文章
基于jquery實現(xiàn)動態(tài)豎向柱狀條特效
很多數(shù)據(jù)統(tǒng)計效果中,柱狀條方式的算是比較常見的一種,形象直觀,下面就是一段能夠?qū)崿F(xiàn)此功能的代碼實例,并且具有一定的動態(tài)效果,感興趣的朋友可以參考一下2016-02-02
jquery中$.fn和圖片滾動效果實現(xiàn)的必備知識總結(jié)
圖片滾動效果相信大家都使用過,看上去很簡單的一個效果,如果想熟練的掌握必須知道jquery、IIFE、setInterval等基礎(chǔ)以及$.fn用法,下面這篇文章主要介紹了關(guān)于jquery中$.fn和圖片滾動效果制作的必備知識,需要的朋友可以參考下。2017-04-04
jquery中獲得$.ajax()事件返回的值并添加事件的方法
如果想獲得$.ajax()中返回的值,直接用在success:funciton(){return xx} 是不可以的,要想獲得xx的值,要在script中,使用全局變量。利用全局變量引出xx的值。2010-04-04
jQuery插件DataTables分頁開發(fā)心得體會
這篇文章主要為大家分享了jQuery插件DataTables分頁開發(fā)心得體會,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
jquery+css實現(xiàn)的紅色線條橫向二級菜單效果
這篇文章主要介紹了jquery+css實現(xiàn)的紅色線條橫向二級菜單效果,界面美觀大方,簡潔實用,通過jquery遍歷及切換頁面元素實現(xiàn)這一功能,需要的朋友可以參考下2015-08-08

