function show(){var iWidth = document.documentElement.clientWidth;//获取浏览器宽度var iHeight = document.documentElement.clientHeight;//获取浏览器高度 var oShow = document.getElementById('show');oShow.style.display = 'block';oShow.style.left = (iWidth-302)/2+"px";//居中横坐标oShow.style.top = (iHeight-202)/2+"px";//居中纵坐标var oClose = document.createElement("span");oClose.innerHTML = "×";oShow.appendChild(oClose);oClose.onclick = function(){oShow.style.display = 'none';oShow.removeChild(this);}}点击下面运行直接查看效果
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
function show(){var iWidth = document.documentElement.clientWidth;var iHeight = document.documentElement.clientHeight; var bgObj = document.createElement("div");//创建背景层bgObj.setAttribute("id","bgbox");bgObj.style.width = iWidth+"px";bgObj.style.height =Math.max(document.body.clientHeight, iHeight)+"px";document.body.appendChild(bgObj);//将创建的层插入body中 var oShow = document.getElementById('show');oShow.style.display = 'block';oShow.style.left = (iWidth-302)/2+"px";oShow.style.top = (iHeight-202)/2+"px"; var oClosebtn = document.createElement("span");oClosebtn.innerHTML = "×";oShow.appendChild(oClosebtn); function oClose(){oShow.style.display = 'none';oShow.removeChild(oClosebtn);document.body.removeChild(bgObj);} oClosebtn.onclick = oClose;bgObj.onclick = oClose;}点击下面运行直接查看效果
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
function getEvent(){return window.event || arguments.callee.caller.arguments[0];// 获得事件Event对象,用于兼容IE和FireFox} document.onkeyup = function(){var event = getEvent();if (event.keyCode == 27){oClose();}}点击下面运行直接查看效果
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
var moveX = 0;var moveY = 0;var moveTop = 0;var moveLeft = 0;var moveable = false;var docMouseMoveEvent = document.onmousemove;var docMouseUpEvent = document.onmouseup;titleBar = document.getElementById('titlebar');titleBar.onmousedown = function() {var evt = getEvent();moveable = true; moveX = evt.clientX;moveY = evt.clientY;moveTop = parseInt(oShow.style.top);moveLeft = parseInt(oShow.style.left); document.onmousemove = function() {if (moveable) {var evt = getEvent();var x = moveLeft + evt.clientX - moveX;var y = moveTop + evt.clientY - moveY;if ( x 0 &&( x + 302 iWidth) && y 0 && (y + 202 iHeight) ) {oShow.style.left = x + "px";oShow.style.top = y + "px";}}};document.onmouseup = function () { if (moveable) { document.onmousemove = docMouseMoveEvent;document.onmouseup = docMouseUpEvent;moveable = false; moveX = 0;moveY = 0;moveTop = 0;moveLeft = 0;} };}点击下面运行直接查看效果
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
欢迎大家多提改进意见或建议,共同学习和探讨
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)