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

ModelDialog JavaScript模態(tài)對(duì)話框類代碼

 更新時(shí)間:2011年04月17日 01:13:29   作者:  
ModelDialog JavaScript模態(tài)對(duì)話框類代碼,需要的朋友可以參考下。
/**
* JavaScript ModelDialog v0.1
*
* new ModelDialog({
* caption 標(biāo)題 '對(duì)話框標(biāo)題'(默認(rèn))
* template 主體內(nèi)容 ''(默認(rèn))
* dialogCls 對(duì)話框className 'md-dialog'(默認(rèn))
* headCls 頭部className 'md-head'(默認(rèn))
* btnCloseCls 關(guān)閉按鈕className 'md-close'(默認(rèn))
* bodyCls 主體className 'md-body'(默認(rèn))
* shadowBg 遮蓋層背景色 'gray'(默認(rèn))
* shadowOpy 遮蓋層透明的 0.2(默認(rèn))
* dragable 是否可拖拽 true(默認(rèn))
* dragInWin 是否僅在窗口內(nèi)拖動(dòng) (true)默認(rèn) 與area互斥
* area [minX,maxX,minY,maxY] 與dragInWin互斥
* });
*/


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

/**
* JavaScript ModelDialog v0.4
* Copyright (c) 2010 snandy
* Blog: http://snandy.javaeye.com/
* QQ群: 34580561
* Date: 2010-09-08
*
*
* new ModelDialog({
* caption 標(biāo)題 '對(duì)話框標(biāo)題'(默認(rèn))
* template 主體內(nèi)容 ''(默認(rèn))
* dialogCls 對(duì)話框className 'md-dialog'(默認(rèn))
* headCls 頭部className 'md-head'(默認(rèn))
* btnCloseCls 關(guān)閉按鈕className 'md-close'(默認(rèn))
* bodyCls 主體className 'md-body'(默認(rèn))
* shadowBg 遮蓋層背景色 'gray'(默認(rèn))
* shadowOpy 遮蓋層透明的 0.2(默認(rèn))
* dragable 是否可拖拽 true(默認(rèn))
* dragInWin 是否僅在窗口內(nèi)拖動(dòng) (true)默認(rèn) 與area互斥
* area [minX,maxX,minY,maxY] 與dragInWin互斥
* });
*/
ModelDialog =
function(){
var px = 'px';
var isIE = /msie/.test(navigator.userAgent.toLowerCase());

function getViewSize(){
return {w: window['innerWidth'] || document.documentElement.clientWidth,
h: window['innerHeight'] || document.documentElement.clientHeight}
}
function getFullSize(){
var w = Math.max(document.documentElement.clientWidth ,document.body.clientWidth) + Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
var h = Math.max(document.documentElement.clientHeight,document.body.clientHeight) + Math.max(document.documentElement.scrollTop, document.body.scrollTop);
w = Math.max(document.documentElement.scrollWidth,w);
h = Math.max(document.documentElement.scrollHeight,h);
return {w:w,h:h};
}
function $(tag){
return new $.prototype.init(tag);
}
$.prototype = {
init : function(tag){
this[0] = document.createElement(tag);
return this;
},
setCls : function(cls){
this[0].className = cls;
return this;
},
setSty : function(name,val){
name=='opacity' ?
isIE ?
this[0].style.filter = 'Alpha(Opacity=' + val*100 + ')' :
this[0].style.opacity = val :
this[0].style[name] = val;
return this;
},
css : function(str){
this[0].style.cssText = str;
return this;
},
html : function(str){
this[0].innerHTML = str;
return this;
}
}
$.prototype.init.prototype = $.prototype;

function ModelDialog(opt){
this.dialogCls = opt.dialogCls || 'md-dialog';
this.headCls = opt.headCls || 'md-head';
this.btnCloseCls = opt.btnCloseCls || 'md-close';
this.bodyCls = opt.bodyCls || 'md-body';
this.shadowBg = opt.shadowBg || 'gray';
this.shadowOpy = opt.shadowOpy || '0.2';
this.caption = opt.caption || "對(duì)話框標(biāo)題";
this.template = opt.template || '';
this.dragable = opt.dragable != false;
this.dragInWin = opt.dragInWin != false;
this.area = opt.area;
this.dialog = null;
this.head = null;
this.label = null;
this.btnClose = null;
this.body = null;
this.shadow = null;
this.init();
}
ModelDialog.prototype = {
init : function(){
var _this = this;
this.dialog = $('div').setCls(this.dialogCls).css('position:absolute;z-index:100;')[0];
this.head = $('div').setCls(this.headCls)[0];
this.label = $('label').html(this.caption)[0];
this.btnClose = $('div').setCls(this.btnCloseCls)[0];
this.on(this.btnClose,'click',function(){
_this.onClose();
});
this.head.appendChild(this.label);
this.head.appendChild(this.btnClose);
this.body = $('div').setCls(this.bodyCls)[0];
this.setContent(this.template);
this.dialog.appendChild(this.head);
this.dialog.appendChild(this.body);
this.createShadow();
document.body.appendChild(this.shadow);
document.body.appendChild(this.dialog);
this.moveToCenter();
// 計(jì)算拖拽范圍
// 標(biāo)準(zhǔn)模式下:clientWidth=width+padding;offsetWidth=width+padding+border
if(this.dragable){
if(this.dragInWin){
var maxX = getViewSize().w - this.dialog.offsetWidth;
var maxY = getViewSize().h - this.dialog.offsetHeight;
this.dragdrop(this.dialog,{
bridge : this.head,
area : [0,maxX,0,maxY]
});
return;
}
if(this.area){
this.dragdrop(this.dialog,{
bridge : this.head,
area : this.area
});
return;
}
this.dragdrop(this.dialog,{
bridge : this.head
});

}

},
destroy : function(){
this.dialog = null;
this.head = null;
this.label = null;
this.btnClose = null;
this.body = null;
this.shadow = null;
},
createShadow : function(){
var str = 'position:absolute;left:0px;top:0px;z-index:1' +
';width:' + getFullSize().w + px +
';height:' + getFullSize().h + px +
';background:' + this.shadowBg +
';opacity:' + this.shadowOpy +
';filter:Alpha(Opacity=' + this.shadowOpy*100 + ');';
var _this = this;
this.shadow = $("div").setCls('md-shadow').css(str)[0];
this.on(window,'resize',function(){
_this.shadow.style.width = getFullSize().w + px;
_this.shadow.style.height = getFullSize().h + px;
_this.moveToCenter();
});
},
moveTo : function(x, y){
this.dialog.style.left = x + px;
this.dialog.style.top = y + px;
},
moveToCenter : function(){
var size = getViewSize();
var x = (size.w-50)/2 - (this.dialog.clientWidth-50)/2;
var y = (size.h- 50)/2 - (this.dialog.clientHeight-50)/2 + document.documentElement.scrollTop;
this.moveTo(x, y);
},
setCaption : function(v){
this.caption = v;
this.label.innerHTML = v;
},
setContent : function(str){
this.template = str;
this.body.innerHTML = str;
},
onClose : function(){
document.body.removeChild(this.dialog);
document.body.removeChild(this.shadow);
if(this['onbi']){
this.onbi();
}
this.destroy();
},
on : function(el, type, fn){
el.addEventListener ?
el.addEventListener(type, fn, false) :
el.attachEvent ?
el.attachEvent("on" + type, fn) :
el['on'+type] = fn;
},
un : function(el,type,fn){
el.removeEventListener ?
el.removeEventListener(type, fn, false) :
el.detachEvent ?
el.detachEvent("on" + type, fn) :
el['on'+type] = null;
},
dragdrop : function(){
return function(el,opt){
var _this=this, ele, diffX, diffY, dragX=true,dragY=true, minX, maxX, minY, maxY, bridge;
ele = el;
opt && opt.dragX===false && (dragX=false);
opt && opt.dragY===false && (dragY=false);
opt && opt.area && typeof opt.area[0]==='number' && (minX=opt.area[0]);
opt && opt.area && typeof opt.area[1]==='number' && (maxX=opt.area[1]);
opt && opt.area && typeof opt.area[2]==='number' && (minY=opt.area[2]);
opt && opt.area && typeof opt.area[3]==='number' && (maxY=opt.area[3]);
opt && opt.bridge && (bridge=opt.bridge);
ele.style.position = 'absolute';
bridge ?
this.on(bridge,'mousedown',mousedown) :
this.on(ele,'mousedown',mousedown);
function mousedown(e){
e = e || window.event;
ele.style.cursor = 'pointer';
if(ele.setCapture){//IE
_this.on(ele, "losecapture", mouseup);
ele.setCapture();
e.cancelBubble = true; //IE
}else if(window.captureEvents){//標(biāo)準(zhǔn)DOM
e.stopPropagation();
_this.on(window, "blur", mouseup);
e.preventDefault();
}
_x = e.clientX;
_y = e.clientY;
diffX = e.clientX - ele.offsetLeft;
diffY = e.clientY - ele.offsetTop;
_this.on(document,'mousemove',mousemove);
_this.on(document,'mouseup',mouseup);
}
function mousemove(e){
e = e || window.event;
var moveX = e.clientX - diffX,
moveY = e.clientY - diffY;
moveX < minX && (moveX = minX); // left 最小值
moveX > maxX && (moveX = maxX); // left 最大值
moveY < minY && (moveY = minY); // top 最小值
moveY > maxY && (moveY = maxY); // top 最大值

dragX && (ele.style.left = moveX + 'px');
dragY && (ele.style.top = moveY + 'px');
}
function mouseup(e){
ele.style.cursor = 'default';
_this.un(document,'mousemove',mousemove);
_this.un(document,'mouseup',mouseup);
if(ele.releaseCapture){//IE
_this.un(ele, "losecapture", mouseup);
ele.releaseCapture();
}
if(window.releaseEvents){//標(biāo)準(zhǔn)DOM
_this.un(window, "blur", mouseup);
}
}
}
}()

}
return ModelDialog;
}();

演示地址 http://demo.jb51.net/js/2011/ModelDialog/index.html
打包下載地址 http://www.dbjr.com.cn/jiaoben/35245.html

相關(guān)文章

  • JS庫(kù)之Three.js 簡(jiǎn)易入門(mén)教程(詳解之一)

    JS庫(kù)之Three.js 簡(jiǎn)易入門(mén)教程(詳解之一)

    three.js是一款webGL框架,由于其易用性被廣泛應(yīng)用。下面腳本之家小編通過(guò)案例給大家闡述three.js的基本配置方法,具體內(nèi)容詳情大家參考下本文吧
    2017-09-09
  • 如何提高Dom訪問(wèn)速度

    如何提高Dom訪問(wèn)速度

    在瀏覽器中對(duì)于Dom的操作和普通的腳本的操作處于兩個(gè)不同的dll中,兩個(gè)dll的交互是比較耗時(shí)的,優(yōu)化對(duì)Dom的操作可以提高腳本的執(zhí)行速度。本文是對(duì)如何優(yōu)化的一些總結(jié)。下面跟著小編一起來(lái)看下吧
    2017-01-01
  • JavaScript中的方法調(diào)用詳細(xì)介紹

    JavaScript中的方法調(diào)用詳細(xì)介紹

    這篇文章主要介紹了JavaScript中的方法調(diào)用詳細(xì)介紹,JavaScript中,如果function屬于一個(gè)對(duì)象,那么通過(guò)對(duì)象來(lái)訪問(wèn)該function的行為稱之為“方法調(diào)用”,需要的朋友可以參考下
    2014-12-12
  • 許愿墻中用到的函數(shù)

    許愿墻中用到的函數(shù)

    許愿墻中用到的函數(shù)...
    2006-10-10
  • javascript replace()正則替換實(shí)現(xiàn)代碼

    javascript replace()正則替換實(shí)現(xiàn)代碼

    javascript-replace()基礎(chǔ),一次完成將"<,>"替換"&lt;&gt;"實(shí)例
    2010-02-02
  • childNodes.length與children.length的區(qū)別

    childNodes.length與children.length的區(qū)別

    childNodes.length與children.length的值常不一樣。
    2009-05-05
  • javascript過(guò)濾危險(xiǎn)腳本方法

    javascript過(guò)濾危險(xiǎn)腳本方法

    腳本藏身之處不過(guò)有四: 1、<script>標(biāo)簽、<link>標(biāo)簽、<style>標(biāo)簽、iframe標(biāo)簽 2、on開(kāi)頭的標(biāo)簽屬性 3、javascript(vbscript)偽協(xié)議 4、css的epression
    2008-08-08
  • 請(qǐng)求時(shí)token過(guò)期自動(dòng)刷新token操作

    請(qǐng)求時(shí)token過(guò)期自動(dòng)刷新token操作

    這篇文章主要介紹了請(qǐng)求時(shí)token過(guò)期自動(dòng)刷新token操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • 淺談如何使用 webpack 優(yōu)化資源

    淺談如何使用 webpack 優(yōu)化資源

    本篇文章主要介紹了淺談如何使用 webpack 優(yōu)化資源,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • 只需五句話搞定JavaScript作用域(經(jīng)典)

    只需五句話搞定JavaScript作用域(經(jīng)典)

    javascript作用域是前端開(kāi)發(fā)比較難理解的知識(shí)點(diǎn),下面小編給大家提供五句話幫助大家很快的了解js作用域,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧
    2016-07-07

最新評(píng)論