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 ...
随机推荐
- 你我公益模式系统APP开发
你我公益模式系统APP开发(微or电 158.1500.1390 小凡团队)你我公益系统开发,你我公益系统模式定制,你我公益系统开发软件,你我公益平台系统开发. 互联网世界无边无界,互联网创业者应敢于 ...
- jquery makearray()使用
makearray(),转换一个类似数组的对象成为真正的JavaScript数组.首先看看jquery中array的定义 makeArray: function( arr, results ) { v ...
- Java面向对象总复习-QuickHit
1.创建玩家级别类Level.java package com.bdqn; /** * 1.玩家级别类 * @author pc * */ public class Level { /** * 级别号 ...
- OC之消息调用过程
Bird * aBird = [[Bird alloc] init]; [aBird fly]; 中对 fly 的调用,编译器通过插入一些代码,将之转换为对方法具体实现 IMP 的调用,这个 IMP ...
- ural 1073.Square Country(动态规划)
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- 7.编写Java应用程序。首先,定义一个Print类,它有一个方法void output(int x),如果x的值是1,在控制台打印出大写的英文字母表;如果x的值是2,在 控制台打印出小写的英文字母表。其次,再定义一个主类——TestClass,在主类 的main方法中创建Print类的对象,使用这个对象调用方法output ()来打印出大 小写英文字母表。
package com.bao; public class Print1 { int x; void output() { if(x==1) { System.out.println("AB ...
- ASP.NET中的Excel操作(NPOI方式)
代码准备: 一:实体准备 代码如下: /// <summary> /// 一个能添加到将要导出到指定行的实体类型规范 /// data:{int StartColIndex ? 0, in ...
- JS 经典代码段总结 start from 2016-08-22
1.for(var i = 0, max = myArray.length; i < max ; i++){ //用myArrayy[i]来做点什么 } 用max存储myArray的长度,防止每 ...
- Maven快速搭建GUI项目
一.eclipse安装好maven插件,并将maven集成到eclipse之后,用maven的archetype,搭建好一个maven-archetype-queckstart项目的骨架. 二.可执行 ...
- mac 文件路径问题
Finder栏显示访问路径 操作步骤: 打开“终端”(应用程序->实用工具),输入以下两条命令: defaults write com.apple.finder _FXShowPosixPath ...