国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery 彈出登錄窗口實現(xiàn)代碼

2019-11-21 00:52:40
字體:
供稿:網(wǎng)友
主要層左右居中,設(shè)置left等于窗口寬除二減去自身層寬除二就居中了,至于窗口上下居中我沒做到,固定了top等于滾動條隱去的 scrollTop加上50px;

當(dāng)事件觸發(fā)這個類時,首先判斷一下兩個層是否已經(jīng)append到body里面,否則每次觸發(fā)它就一直增加增加了。設(shè)置了五個參數(shù)title、 content、width、height、cssName,它們分別定義了層標(biāo)題、層內(nèi)內(nèi)容、層寬、層高、層內(nèi)容的樣式名。層內(nèi)內(nèi)容又設(shè)置了url、 text、id、iframe四種加載方式,通過ajax以get或post加載目標(biāo)url的html內(nèi)容,text是直接在事件里寫入內(nèi)容,而id是取 得頁面上某個id里面的html顯示到彈出層里,iframe都知道是在層里面以框架顯示目標(biāo)url了。往往彈出層里面的內(nèi)容樣式也是各種各樣的,所以加 了一個參數(shù)cssName,通過它就可以把層內(nèi)的內(nèi)容給排好了。

一,彈出層的html如下:
復(fù)制代碼 代碼如下:

<div id="floatBoxBg">
<div id="floatBox" class="floatBox">
<div class="title"><h4>標(biāo)題</h4><span>關(guān)閉</span></div>
<div class="content">內(nèi)容</div>
</div>
</div>

其對應(yīng)樣式如下:
復(fù)制代碼 代碼如下:

#floatBoxBg {
display:none;
width:100%;
height:100%;
background:#000;
position:absolute;
top:0;
left:0;
}
.floatBox {
border:#0C7FDA 5px solid;
width:300px;
position:absolute;
top:50px;
left:40%;
z-index:1000;
}
.floatBox .title {
height:23px;
padding:7px 10px 0;
color:#fff;
background-attachment: scroll;
background-image:url(../images/dialog_bg.gif);
background-repeat: repeat-x;
background-position: 0px 0px;
}
.floatBox .title h4 {
float:left;
padding:0;
margin:0;
font-size:14px;
line-height:16px;
}
.floatBox .title span {
float:right;
cursor:pointer;
vertical-align:middle;
margin-bottom:2px;
}
.floatBox .content {
padding:20px 15px;
background:#fff;
}

二,彈出窗口js文件如下:
復(fù)制代碼 代碼如下:

// JavaScript Document

var dialogFirst=true;
function dialog(title,content,width,height,cssName){

if(dialogFirst==true){
var temp_float=new String;
temp_float="<div id=/"floatBoxBg/" style=/"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;/"></div>";
temp_float+="<div id=/"floatBox/" class=/"floatBox/">";
temp_float+="<div class=/"title/"><h4></h4><span><img src=/"/upload/2009-12/20091224021446804.gif/" width=/"22/" height=/"23/" /></span></div>";
temp_float+="<div class=/"content/"></div>";
temp_float+="</div>";
$("body").append(temp_float);
dialogFirst=false;
}

$("#floatBox .title span").click(function(){
$("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
$("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();});
});

$("#floatBox .title h4").html(title);
contentType=content.substring(0,content.indexOf(":"));
content=content.substring(content.indexOf(":")+1,content.length);
switch(contentType){
case "url":
var content_array=content.split("?");
$("#floatBox .content").ajaxStart(function(){
$(this).html("loading...");
});
$.ajax({
type:content_array[0],
url:content_array[1],
data:content_array[2],
error:function(){
$("#floatBox .content").html("error...");
},
success:function(html){
$("#floatBox .content").html(html);
}
});
break;
case "text":
$("#floatBox .content").html(content);
break;
case "id":
$("#floatBox .content").html($("#"+content+"").html());
break;
case "iframe":
$("#floatBox .content").html("<iframe src=/""+content+"/" width=/"100%/" height=/""+(parseInt(height)-70)+"px"+"/" scrolling=/"auto/" frameborder=/"0/" marginheight=/"0/" marginwidth=/"0/"></iframe>");
}

$("#floatBoxBg").show();
$("#floatBoxBg").animate({opacity:"0.5"},"normal");
$("#floatBox").attr("class","floatBox "+cssName);
$("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
$("#floatBox").animate({top:($(document).scrollTop()+50)+"px"},"normal");
}

三,參數(shù)說明
順序參數(shù)功能備注
1title彈出層的標(biāo)題必填,純文本
2content彈出層的內(nèi)容:urlget或post某一頁面里的html,該頁面要求只包含body的子標(biāo)簽
:text直接寫入內(nèi)容
:id顯示頁面里某id的子標(biāo)簽
:iframe層內(nèi)內(nèi)容以框架顯示
3width彈出層的寬必填,css值,比如“200px”
4height彈出層的高如上,但是可用“auto”
5cssName彈出層的css給id floatBox加入的樣式名,層內(nèi)樣式可以通過這個樣式名來定制

四,應(yīng)用
dialog(title,content,width,height,cssName);
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 文成县| 沙坪坝区| 纳雍县| 绥化市| 会泽县| 井研县| 府谷县| 永年县| 普格县| 铜陵市| 格尔木市| 如东县| 曲沃县| 阿拉善左旗| 海安县| 定远县| 崇义县| 黑河市| 中西区| 商河县| 古交市| 句容市| 西吉县| 建瓯市| 道孚县| 静海县| 灯塔市| 张家港市| 杭州市| 乌拉特中旗| 临武县| 新宁县| 南乐县| 怀远县| 泰州市| 绵阳市| 温泉县| 高碑店市| 莱阳市| 霍邱县| 荆州市|