JS模拟窗口
摘自于网络:http://www.cnblogs.com/joinger/articles/1297228.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript">
function $()
{
var arr=new Array();
for (var i=0; i < arguments.length; i++)
{
var aa=arguments[i];
if(typeof(aa)=='string')
{
aa=document.getElementById(aa);
}
if(arguments.length==1)
{
return aa;
}
arr.push(aa);
}
return arr;
}
function Cmsgbox()
{
this.title=null;
this.message=null;
this.left=[];
this.top=[];
this.isminibox=[];
this.width=[];
this.id=0;
this.hover='orange';
this.normal='slategray';
this.dragenable=false;
this.x=0;
this.y=0;
this.curindex=100;
this.actindex=null;
this.modal=true;
this.bgdivobj=null;
}
Cmsgbox.prototype.subwin=function(msg,fcallback,tit,w,l,t,modal,type)
{
var buttoncss="width:69px;height:20px;color:#333;cursor:hand;";
if(type==2)
{
if(modal=="undefined"||modal==null)
modal=false;
this.isminibox[this.id]=false;
}
this.basemsg(tit,msg,w,l,t,modal);
var str="<div id='"+this.id+"csubwin' onmousedown='Cmgbox.totop(this)' style='z-index:"+(this.curindex++)+";position:absolute;border:2px solid "+this.normal+";left:"+this.left[this.id]+"px;top:"+this.top[this.id]+"px;width:"+this.width[this.id]+"px;' >";
str+="<div style='padding-bottom:2px;width:100%;height:16px;color:white;' ";
str+="onmousedown='Cmgbox.begindrag(this)' onmousemove='Cmgbox.ondrag(this)' onmouseup='Cmgbox.enddrag(this)' ";
if(type==2)
str+="ondblclick='Cmgbox.minibox(this.childNodes(1))'";
str+="><div style='float:left;height:16px;overflow:hidden;margin:0px;padding:4px 0px 0px 5px;width:"+(this.width[this.id]-2*14-5)+";'>"+this.title+"</div>";
if(type==2)
str+="<span style='width:14px;font-family:webdings;cursor:hand;' onclick='Cmgbox.minibox(this)'>0</span><span style='width:14px;font-family:webdings;cursor:hand;' onclick='Cmgbox.closediv(this)'>r</span>";
str+="</div><div style='margin:10px 5px 10px 10px;word-break:break-all;'>"+this.message+"</div>";
if(type==0||type=="undefinded"||type==null||type==""||type==1)
{
typestr="<input type='button' style='"+buttoncss+"' id='boxyes' value='确 定' />";
if(type==1)
typestr+=" <input type='button' style='"+buttoncss+"' value='取 消' onclick='Cmgbox.closediv(this)' />";
str+="<div style=text-align:right;margin:0px;padding:7px;padding-right:15px;background:#ccc;'>"+typestr+"</div></div>";
}
if(this.modal)
this.showbgdiv(this.curindex-2);
this.id++;
document.body.insertAdjacentHTML("beforeEnd",str);
if(type!=2)
{
$("boxyes").focus();
$("boxyes").onclick=function()
{
Cmgbox.closediv(this);
if(fcallback)
fcallback();
}
}
}
Cmsgbox.prototype.showbgdiv=function(zindex)
{
var swidth,sheight;
swidth=document.body.offsetWidth+document.body.offsetLeft*2;
if(document.body.clientHeight<screen.height)
sheight=screen.height;
else
sheight=document.body.clientHeight+document.body.offsetTop*2;
var bgobj=document.createElement("div");
bgobj.setAttribute('id','bgdiv');
bgobj.style.position="absolute";
bgobj.style.top="0px";
bgobj.style.background="#ccc";
bgobj.style.filter="progid:dximagetransform.microsoft.alpha(style=3,opacity=25,finishopacity=75)";
bgobj.style.left="0px";
bgobj.style.width=swidth;
bgobj.style.height=sheight;
bgobj.style.zIndex = zindex;
bgobj.oncontextmenu=function(){return false;}
bgobj.ondragstart=function(){return false;}
bgobj.onselectstart=function(){return false;}
document.body.appendChild(bgobj);
this.bgdivobj=bgobj;
}
////////////////////////关闭窗口////////////////////////
Cmsgbox.prototype.closediv=function(obj)
{
if(this.modal)
{
document.body.removeChild(this.bgdivobj);
this.bgdivobj=null;
this.modal=false;
}
obj.parentNode.parentNode.removeNode(true);
}
//////////////////////使窗口出现在最顶端/////////////////////////
Cmsgbox.prototype.totop=function(obj)
{
this.actindex=this.curindex-1;
if(obj.style.zIndex<this.actindex)
obj.style.zIndex=this.curindex++;
}
/////////////////////开始拖动///////////////////////////////////////////
Cmsgbox.prototype.begindrag=function(obj)
{
if(event.button==1)
{
this.dragenable=true;
obj.setCapture();
var box=obj.parentNode;
this.x=event.clientX;
this.y=event.clientY;
box.style.borderColor=this.hover;
obj.style.backgroundColor=this.hover;
box.style.filter="progid:DXImageTransform.Microsoft.shadow(direction=135,color=#8E8E8E,strength=5)";
}
}
///////////////////////////拖动中////////////////////////////////////////
Cmsgbox.prototype.ondrag=function(obj)
{
if(this.dragenable)
{
var box=obj.parentNode;
var i=parseInt(box.id);
var boxleft=event.clientX-this.x+this.left[i];
var boxtop=event.clientY-this.y+this.top[i];
if(boxleft>0&&boxleft+this.width[i]<(document.body.offsetWidth+document.body.offsetLeft*2))
box.style.pixelLeft=boxleft;
if(boxtop>0)
box.style.pixelTop=boxtop;
}
}
//////////////////////////结束拖动/////////////////////////////////
Cmsgbox.prototype.enddrag=function(obj)
{
if(this.dragenable)
{
var box=obj.parentNode;
var i=parseInt(box.id);
this.dragenable=false;
box.style.borderColor=this.normal;
obj.style.backgroundColor=this.normal;
this.left[i]=box.style.pixelLeft;
this.top[i]=box.style.pixelTop;
box.style.filter="";
obj.releaseCapture();
}
}
/////////////////////////窗口最小化///////////////////////////////
Cmsgbox.prototype.minibox=function(obj)
{
var title=obj.parentNode;
var i=parseInt(title.parentNode.id);
if(this.isminibox[i]=!this.isminibox[i])
{
title.nextSibling.style.display="none";
obj.innerHTML="2";
}
else
{
title.nextSibling.style.display="";
obj.innerHTML="0";
}
}
Cmsgbox.prototype.basemsg=function(tit,msg,w,l,t,modal)
{
this.title=tit||"系统消息";
this.message=msg;
if(modal=="undefined"||modal==null)
modal=true;
if(w=="undefined"||w==null||w=="")
w=300;
if(l=="undefined"||l==null||l=="")
l=parseInt((document.body.clientWidth-w)/2);
if(t=="undefined"||t==null||t=="")
t=100+document.body.scrollTop;
this.left[this.id]=l;
this.top[this.id]=t;
this.width[this.id]=w;
this.modal=modal;
}
/////////////////////实例化/////////////////////////////////////
var Cmgbox=new Cmsgbox();
window.subwin=function(msg,tit,w,l,t,modal){Cmgbox.subwin(msg,function(){},tit,w,l,t,modal,2);} //跳出子窗口 例:window.subwin(标题,内容,宽,X坐标,Y坐标,是否模态显示); (默认为非模态)
window.msgbox=function(msg,fcallback,tit,type,modal){return Cmgbox.subwin(msg,fcallback,tit,"","","",modal,type);}//跳出模态选框 例:window.msgbox(标题,内容,类型选择,是否模态显示);(type=0:alert; type=1:confirm)
</script>
<title>无标题文档</title>
<style>
body{}{
font-size:12px;
}
</style>
</head>
<body>
<a href="javascript: window.subwin('tit后。当然也之页全部html标签之后你已经试过放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了 df可能是发现根本不起作用,这就涉及到下一个要注意的问题了。<br><br>2、Build函数的最后,你是通过 insertAdjacentHTML()方法把生成的代码放在了网le','title')">跑出一个框</a>
<a href="javascript:window.subwin('你已经l标签之后你已经试过所以应该把对无法获取,方,也就是xWinxx赋值这个工 作放在窗口第一次初始化完成的地放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问试过放在这里','标题')">跑出一个框< /a>
<a href="javascript: window.subwin('放在build语句之后。当然也可能是发现根本不起作用,这就涉及到下一个要注意的问题了。<br>< br>2、Build函数的最后,你是通过insertAdjacentHTML()方法把生成的代码放在了网页全部html标签之后你已经试过放 在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了了网页全部html标','子窗口',600)">跑出一个框</a>
<a href="javascript: window.subwin('页全部htfsdfs导致无法获取,所以应该把对xx赋值这个工作放在窗口第一次初始化完成的地方,也就是xWin函数 中,this.b代码放在了网页全部html标签之后你已经试过ml','要注意的问题了df')">跑出一个框</a>
<a href="javascript: window.msgbox('sdfsdfsdfsdfs导致无法获取,所以应该把对xx赋值这个工作放在窗口第一次初始化完成的地方,也就是xWin 函数中,this.build语句之后把生成的代页全部html标签之后你已经试过放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了 df',function(){alert(true)},'码放在了网',1)">警告框</a>
</body>
</html>
JS模拟窗口的更多相关文章
- Gremlins.js – 模拟用户随机操作的 JS 测试库
Gremlins.js 是基于 JavaScript 编写的 Monkey 测试库,支持 Node.js 平台和浏览器中使用.Gremlins.js 随机模拟用户操作:单击窗口中的任意位置,在表格中输 ...
- js模拟点击打开超链接
js模拟点击打开超链接,页面上有一些锚文本,如果用 JS 批量在新窗口打开. jquery示例: <div class="link"> <a href=" ...
- three.js模拟实现太阳系行星体系
概况如下: 1.SphereGeometry实现自转的太阳: 2.RingGeometry实现太阳系星系的公转轨道: 3.ImageUtils加载球体和各行星贴图: 4.canvas中createRa ...
- js模拟抛出球运动
js练手之模拟水平抛球运动 -匀加速运动 -匀减速运动 模拟运动有些基本的思路,当前所在点的坐标,元素的长宽是多少,向右/向下运动x/y增加,向上/向左运动x/y减少,运动的路程是多少,用什么方程进行 ...
- JS 模拟手机页面文件的下拉刷新
js 模拟手机页面文件的下拉刷新初探 老总说需要这个功能,好吧那就看看相关的东西呗 最后弄出了一个简单的下拉刷新页面的形式,还不算太复杂 查看 demo 要在仿真器下才能看到效果,比如chrome的里 ...
- 由chrome剪贴板问题研究到了js模拟鼠标键盘事件
写在前面 最近公司在搞浏览器兼容的事情,所有浏览器兼容的问题不得不一个人包了.下面来说一下今天遇到的一个问题吧 大家都知道IE下面如果要获得剪贴板里面的信息的话,代码应该如下所示 window.cli ...
- node.js模拟qq漂流瓶
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) node.js模拟简易漂流瓶,页面有扔瓶子和捡瓶子的功能,一个瓶子只能被捡到一次,阅读完就置状态位, ...
- (转)JS浮动窗口(随浏览器滚动而滚动)
原文:http://hi.baidu.com/aiyayaztt/item/4201c55a6b729dced2e10c79 JS浮动窗口(随浏览器滚动而滚动) 往往用于一些联系方式,互动平台模块,随 ...
- css配合js模拟的select下拉框
css配合js模拟的select下拉框 <!doctype html> <html> <head> <meta charset="utf-8&quo ...
随机推荐
- Swift逃逸闭包之见解
Swift 逃匿闭包顾名思义,就是闭包想要逃跑.当闭包作为参数传给一个方法时,在这个方法被调用完后闭包却还没有被执行,而是等到方法执行完后才调用 基本都是跨线程的时候才会有逃逸闭包这个说法.因为异步 ...
- GOPS 2016全球运维大会 • 北京站概况
GOPS 2016全球运维大会上海站已圆满落幕,错过上海站的朋友或许会感到一些遗憾,但是不用担心,在12月16日,GOPS 2016全球运维大会 • 北京站将隆重召开,错过上海在的朋友可以赶上北京站哦 ...
- 《JS权威指南学习总结--8.7 函数属性、方法和构造函数》
内容要点: 在JS程序中,函数是值.对函数执行typeof运算会返回字符串 "function",但是函数是JS中特殊的对象.因为函数也是对象,它们也可以拥有属性和方法,就像普 ...
- 2016年团体程序设计天梯赛-决赛 L1-5. 是不是太胖了(5)
据说一个人的标准体重应该是其身高(单位:厘米)减去100.再乘以0.9所得到的公斤数.已知市斤是公斤的两倍.现给定某人身高,请你计算其标准体重应该是多少?(顺便也悄悄给自己算一下吧……) 输入格式: ...
- JavaScript的正则表达式
1.文本框只能输入数字(不包括小数点) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpas ...
- gsl安装(Linux系统)
1. 在gnu的ftp站点http://ftp.gnu.org/gnu/gsl/ 上, 下载最新的gsl-2.x.tar.gz 2. 解压下载好的gsl-2.x.tar.gz 压缩包,$tar -zx ...
- NSCondition
一.NSCondition是对条件变量和互斥量的一个封装,用于线程之间的同步. 其中的互斥量用于保护对条件变量的修改,条件变量变化以信号量的方式通知其它线程实现线程之间的同步. 二.NSConditi ...
- Struts入门学习(三)---自定义类型转换器
类型转换器是将浏览器传递的参数进行转换为了与服务器端的参数匹配,先举个例子如果我们想往服务器传递日期类型的参数时我们要怎么让浏览器传过去的让服务器明白 我们新建一个类 ConverterTest.ja ...
- Computed Observable的参数
构造计算监控(Constructing a computed observable) 1. ko.computed( evaluator [, targetObject, options] ) eva ...
- Raft详解-启动后运行期间代码
Raft启动后运行期间主要执行两个函数:1.状态监测和转化 func (rf *Raft) Loop() { // Set out as a follower TimeOutConst := 0 fo ...