欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript面向?qū)ο蟮姆绞綄崿F(xiàn)的彈出層效果代碼

 更新時間:2010年01月28日 21:40:36   作者:  
由于本人以前是.net程序員,所以即使現(xiàn)在在做前端,也習(xí)慣于用面向?qū)ο蟮姆绞骄帉慾s腳本,我想如果你以前也是或者現(xiàn)在還是名第三代程序員的話,應(yīng)該對此并不陌生。

說到j(luò)s的面向?qū)ο螅筒坏貌惶岬絧rototype這個js內(nèi)置屬性了(注意:這里的prototype可不是prototype.js),它的作用就是可以動態(tài)的向一個對象(object)添加某種屬性。我現(xiàn)在要做的就是盡可能的讓代碼達(dá)到公用,像繼承啦之類的。好了,這些就不多說了,對prototype不了解的可以搜索下相關(guān)內(nèi)容。

今天要做的是點擊一個html元素讓其彈出一個友好的對話框來,首先要明確兩點,一點是我可能會大量的用到這種方式,甚至不希望出現(xiàn)系統(tǒng)的alert或confirm,第二點就是彈出的內(nèi)容盡量的可以多種化,甚至可以自定義。明確這兩點后,我們就可以寫js代碼了,都是些很初級的東西,如果你要鄙視的話就盡情的鄙視我吧!^.^

首先定義一個簡單的對象:

復(fù)制代碼 代碼如下:

function objDIV() {
this.bgdiv ;
this.infodiv ;
}

首先,我們希望彈出一個遮罩層,我給它命名openBackDiv();
復(fù)制代碼 代碼如下:

function openBackDiv(txbdiv) {
txbdiv.bgdiv = document.createElement("div");
txbdiv.bgdiv.setAttribute("id", "overDiv");
txbdiv.bgdiv.innerHTML = "<iframe frameborder=\"no\" class=\"overPanel\" id=\"ifrover\"></iframe>";

}

再者,把它添加到剛剛定義的對象的prototype里去(openBG()):
復(fù)制代碼 代碼如下:

objDIV.prototype.openBG = function() {
openBackDiv(this);
document.body.appendChild(this.bgdiv);
this.bgdiv.style.display = "block";
this.bgdiv.style.width = document.documentElement.clientWidth + "px";
this.bgdiv.style.height = document.documentElement.scrollHeight + "px";
}

再就是添加彈出信息層的方法,和上面一樣做就行了。所以才說這個是很基礎(chǔ)的東西,好像確實沒啥好說的,直接上代碼吧!

這是一個正在加載的彈出層,有點粗糙.
復(fù)制代碼 代碼如下:

function openLoadDiv(txbdiv) {
txbdiv.infodiv = document.createElement("div");
txbdiv.infodiv.setAttribute("id", "div_info");
txbdiv.infodiv.innerHTML = "<div style=\" line-height:1.5;background:url(../images/tips-top-bg.gif) repeat-x; height:54px; text-align:center;\"><img border=\"0\" src=\"../images/xtts.gif\" /></div><div style='padding:20px; font-size:14px; color:#b44201;'><div style='width:100px; float:left;margin:60px 0 0 60px; height:80px;'><img src='/images/business/loading.gif' width='100px' height='100' border='0'/></div><div style='float:left; width:250px;margin:90px 0 0 20px;'><p>請稍等,正在處理中...</p></div></div></div>";
document.body.appendChild(txbdiv.infodiv);
txbdiv.infodiv.style.width = "550px";
txbdiv.infodiv.style.height = "270px";
txbdiv.infodiv.style.fontSize = "14px";
txbdiv.infodiv.style.position = "absolute";
txbdiv.infodiv.style.background = "#fff";
txbdiv.infodiv.style.zIndex = "9999";
centerobject();//居中的方法
}
objDIV.prototype.openLoading = function() { this.openBG(); openLoadDiv(this); }


做完這些后一個簡單的彈出加載層就完成了.是不是有點成就感了,那么接著完成其他的工作吧!既然都彈出了,總得在某個時刻把它們移掉吧,下面就是移除這些層的方法。
復(fù)制代碼 代碼如下:

objDIV.prototype.removeBG = function() {
if (this.bgdiv || document.getElementById("overDiv")) {
if (this.bgdiv) {
document.body.removeChild(this.bgdiv);
} else {
document.body.removeChild(document.getElementById("overDiv"));
}
}
}
objDIV.prototype.removeInfo = function() {
this.removeBG();
if (this.infodiv) {
document.body.removeChild(this.infodiv);
} else {
document.body.removeChild(document.getElementById("div_info"));
}
}

如果想彈出不同層信息的話,就可以添加不同的prototype屬性。
完整的代碼
[code]

//******js彈出層提示txb20100110********//
function objDIV() {
this.bgdiv ;
this.infodiv ;
}
objDIV.prototype.openBG = function() {
openBackDiv(this);
document.body.appendChild(this.bgdiv);
this.bgdiv.style.display = "block";
this.bgdiv.style.width = document.documentElement.clientWidth + "px";
this.bgdiv.style.height = document.documentElement.scrollHeight + "px";
}
objDIV.prototype.openRegInfo = function() {
this.openBG();
openDiv(this);
}
objDIV.prototype.openLoading = function() {
this.openBG();
openLoadDiv(this);
}
objDIV.prototype.openLoad = function() {
openLoadDiv(this);
}
objDIV.prototype.removeBG = function() {
if (this.bgdiv || document.getElementById("overDiv")) {
if (this.bgdiv) {
document.body.removeChild(this.bgdiv);
} else {
document.body.removeChild(document.getElementById("overDiv"));
}
}
}
objDIV.prototype.removeInfo = function() {
this.removeBG();
if (this.infodiv) {
document.body.removeChild(this.infodiv);
} else {
document.body.removeChild(document.getElementById("div_info"));
}
}

function openLoadDiv(txbdiv) {
txbdiv.infodiv = document.createElement("div");
txbdiv.infodiv.setAttribute("id", "div_info");
txbdiv.infodiv.innerHTML = "<div style=\" line-height:1.5;background:url(tips-top-bg.gif) repeat-x; height:54px; text-align:center;\"><img border=\"0\" src=\"xtts.gif\" /></div><div style='padding:20px; font-size:14px; color:#b44201;'><div style='width:100px; float:left;margin:60px 0 0 60px; height:80px;'><img src='loading.gif' width='100px' height='100' border='0'/></div><div style='float:left; width:250px;margin:90px 0 0 20px;'><p>請稍等,正在處理中...</p></div></div></div>";
document.body.appendChild(txbdiv.infodiv);
txbdiv.infodiv.style.width = "550px";
txbdiv.infodiv.style.height = "270px";
txbdiv.infodiv.style.fontSize = "14px";
txbdiv.infodiv.style.position = "absolute";
txbdiv.infodiv.style.background = "#fff";
txbdiv.infodiv.style.zIndex = "9999";

centerobject();
}

function openBackDiv(txbdiv) {
txbdiv.bgdiv = document.createElement("div");
txbdiv.bgdiv.setAttribute("id", "overDiv");
//alert(document.documentElement.clientWidth);
txbdiv.bgdiv.innerHTML = "<iframe frameborder=\"no\" class=\"overPanel\" id=\"ifrover\"></iframe>";
//"<div id=\"overPanel\" > <iframe frameborder=\"no\" class=\"overPanel\" id=\"ifrover\"></iframe></div>";
//txbdiv.openBG();
}
function openDiv(txbdiv) {
//txbdiv.openBG();
txbdiv.infodiv = document.createElement("div");
txbdiv.infodiv.setAttribute("id", "div_info");
txbdiv.infodiv.innerHTML = "<div style=\" line-height:1.5;background:url(tips-top-bg.gif) repeat-x; height:54px; text-align:center;\"><img border=\"0\" src=\"xtts.gif\" /></div><div style=\"padding:20px;\"><div style=\"width:120px; float:left;\"><img src=\"xin.gif\" /></div><div style=\"float:right; width:350px;color:#b44201;\" id=\"showdivinfo\"><p>恭喜您,注冊成功!</p><p>請牢記您的賬號:<font color=\"#b44201\" id=\"orpai_ID\">5678537</font></p></div><div style=\"margin:0 auto;\"><input type='button' value='確認(rèn)' onclick='new objDIV().removeInfo();'/></div></div>";
document.body.appendChild(txbdiv.infodiv);
txbdiv.infodiv.style.width = "550px";
txbdiv.infodiv.style.height = "270px";
txbdiv.infodiv.style.fontSize = "14px";
txbdiv.infodiv.style.position = "absolute";
txbdiv.infodiv.style.background = "#fff";
txbdiv.infodiv.style.zIndex = "9999";

centerobject();
}

function centerobject() {
if (document.getElementById("overDiv")) {
var objdiv = document.getElementById("overDiv").style;
objdiv.height = document.documentElement.scrollHeight + "px";
objdiv.left = parseInt((document.documentElement.clientWidth - parseInt(objdiv.width)) / 2) + "px";
//alert(document.documentElement.scrollHeight)
objdiv.top = parseInt((document.documentElement.clientHeight - parseInt(objdiv.height)) / 2) + "px";
}
if (document.getElementById("div_info")) {
var div_info = document.getElementById("div_info").style;
div_info.left = parseInt((document.documentElement.clientWidth - parseInt(div_info.width)) / 2) + "px";
div_info.top = parseInt((document.documentElement.clientHeight - parseInt(div_info.height)) / 2) + "px";
}
}

function centerDIV(objId) {
if (document.getElementById(objId)) {
var objdiv = document.getElementById(objId).style;
objdiv.height = document.getElementById(objId).scrollHeight + "px";
objdiv.width = document.getElementById(objId).scrollWidth + "px";
objdiv.left = parseInt((document.documentElement.clientWidth - parseInt(objdiv.width)) / 2) + "px";
//alert(document.documentElement.scrollHeight)
objdiv.top = parseInt((document.documentElement.clientHeight - parseInt(objdiv.height))/ 2) + "px";

}
}

function centerObj(obj) {
if (obj) {
var objdiv = obj.style;
objdiv.height = obj.scrollHeight + "px";
objdiv.width = obj.scrollWidth + "px";
objdiv.left = parseInt((document.documentElement.clientWidth - parseInt(objdiv.width)) / 2) + "px";
//alert(document.documentElement.scrollHeight)
objdiv.top = parseInt((document.documentElement.clientHeight - parseInt(objdiv.height)) / 2) + "px";
}
}
//window.onresize = centerobject;
[code]
演示地址 http://demo.jb51.net/js/opendiv/opendiv.htm

相關(guān)文章

  • 面向?qū)ο蟮腏avascript之一(初識Javascript)

    面向?qū)ο蟮腏avascript之一(初識Javascript)

    Javascript是一門極富表現(xiàn)力的語言,在當(dāng)今大行其道的Web浪潮中扮演著非常關(guān)鍵的作用。合理、高效地利用這門技術(shù),可以讓我們的Web世界多姿多彩。首先,我們認(rèn)識一下這門技術(shù)的幾個獨特的特性
    2012-01-01
  • javascript 面向?qū)ο缶幊?function也是類

    javascript 面向?qū)ο缶幊?function也是類

    function在javascript中用來創(chuàng)建函數(shù)或方法,但要想實現(xiàn)面向?qū)ο蠓绞降木幊?,類是不可或缺的角色之一,而且是主角?/div> 2009-09-09
  • CCPry JS類庫 代碼

    CCPry JS類庫 代碼

    CCPry JS類庫 代碼,需要的朋友可以參下。
    2009-10-10
  • javascript復(fù)制對象使用說明

    javascript復(fù)制對象使用說明

    javascript復(fù)制對象使用說明,需要的朋友可以參考下。
    2011-06-06
  • javascript 面向?qū)ο缶幊袒A(chǔ):繼承

    javascript 面向?qū)ο缶幊袒A(chǔ):繼承

    "繼承是面向?qū)ο箝_發(fā)的又一個重要概念,它可以將現(xiàn)實生活的概念對應(yīng)帶程序邏輯中"?!? 雖然在JavaScript中沒有專門的機(jī)制來實現(xiàn)類的繼承,但可以通過拷貝一個類的prototype 到另外一個類來實現(xiàn)繼承”。
    2009-08-08
  • [推薦]javascript 面向?qū)ο蠹夹g(shù)基礎(chǔ)教程

    [推薦]javascript 面向?qū)ο蠹夹g(shù)基礎(chǔ)教程

    看了很多介紹javascript面向?qū)ο蠹夹g(shù)的文章,很暈.為什么?不是因為寫得不好,而是因為太深奧. javascript中的對象還沒解釋清楚怎么回事,一上來就直奔主題,類/繼承/原型/私有變量....
    2009-03-03
  • 最新評論