Js弹出浮动窗口,支持鼠标拖动和关闭 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
/**
关于一些参数说明:
*bodycontent:要在窗口显示的内容,dom对象
*title:窗口标题,字符串类型
*removeable:窗口能否拖动,布尔类型
*注意:内容窗体的高度是height-30px,请计算好你要显示的内容的高度和宽度。弹出窗的id为"223238909",所以你的页面不要再取值为"223238909"的id了,以防js执行出错*/
function createdialog{
if==null){
/*创建窗口的组成元素*/
var dialog = document.createElement;
var dialogtitlebar= document.createElement;
var dialogbody = document.createElement;
var dialogtitleimg = document.createElement;
var dialogtitle = document.createElement;
var dialogclose = document.createElement;
var closeaction = document.createElement;
/*为窗口设置一个id,id如此怪异是为了尽量避免与其他用户取的id相同而出错*/
dialog.id = "223238909";
/*组装对话框标题栏,按从里到外的顺序组装*/
dialogtitle.innerHTML = title;
dialogtitlebar.appendChild;
dialogtitlebar.appendChild;
dialogtitlebar.appendChild;
dialogclose.appendChild;
/*组装对话框主体内容*/
if{
bodycontent.style.display = "block";
dialogbody.appendChild;
}
/*组装成完整的对话框*/
dialog.appendChild;
dialog.appendChild;
/*设置窗口组成元素的样式*/
var templeft,temptop,tempheight//窗口的位置(将窗口放在页面中间的辅助变量)
var dialogcssText,dialogbodycssText;//拼出dialog和dialogbody的样式字符串
templeft = /2;
temptop = /2;
tempheight= height-30;
dialogcssText= "position:absolute;background:#65c294;padding:1px;border:4px;top:"+temptop+"px;left:"+templeft+"px;height:"+height+"px;width:"+width+"px;";
dialogbodycssText = "width:100%;background:#ffffff;"+"height:" + tempheight + "px;";
dialog.style.cssText = dialogcssText;
dialogtitlebar.style.cssText = "height:30px;width:100%;background:url repeat;cursor:move;";
dialogbody.style.cssText = dialogbodycssText;
dialogtitleimg.style.cssText = "float:left;height:20px;width:20px;background:url;"+"display:block;margin:4px;line-height:20px;";
dialogtitle.style.cssText = "font-size:16px;float:left;display:block;margin:4px;line-height:20px;";
dialogclose.style.cssText = "float:right;display:block;margin:4px;line-height:20px;";
closeaction.style.cssText = "height:20px;width:24px;border-width:1px;"+"background-image:url;cursor:pointer;";
/*为窗口元素注册事件*/
var dialogleft = parseInt;
var dialogtop = parseInt;
var ismousedown = false;//标志鼠标是否按下
/*关闭按钮的事件*/
closeaction.onclick = function{
dialog.parentNode.removeChild;
}
/*实现窗口的移动,这段代码很典型,网上很多类似的代码*/
if{
var ismousedown = false;
var dialogleft,dialogtop;
var downX,downY;
dialogleft = parseInt;
dialogtop = parseInt;
dialogtitlebar.onmousedown = function{
ismousedown = true;
downX = e.clientX;
downY = e.clientY;
}
document.onmousemove = function{
if{
dialog.style.top = e.clientY - downY + dialogtop + "px";
dialog.style.left = e.clientX - downX + dialogleft + "px";
}
}
/*松开鼠标时要重新计算当前窗口的位置*/
document.onmouseup = function{
dialogleft = parseInt;
dialogtop = parseInt;
ismousedown = false;
}
}
return dialog;
}//end if
}
</script>
<style>
table{background:#b2d235;}
button{font-size:12px;height:23;background:#ece9d8;border-width:1;}
#linkurl,#linkname,#savelink{width:100px;}
</style>
<body>
点击生成窗口
<script type="text/javascript">
var here = document.getElementById;
var login = document.getElementById;
var clickhere = document.getElementById;
clickhere.onclick = function{
here.appendChild);
}
</script>