JS如何将窗口移动到屏幕外面

我就不想让人看见这个页面窗口,能隐藏更好,不能隐藏就给移动到屏幕外面,JS代码怎么写

<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{margin:0px;padding:0px;}
html,body{overflow:hidden;}
#cont1 {height: 200px;width: 200px;position: absolute;top: 16px;left: 19px;<br>background-color: #090;cursor:move;z-index:1;}
</style>
<script type="text/javascript">
window.onload=function(){
function getObj(d){return document.getElementById(d)}
function drag(obj){
var o=document.getElementById(obj)
var move=false;
o.onselectStart=function(){return false;}
o.onmousedown=function(e){
e=e||event;
this.innerHTML="你按下了鼠标!";
move=true;
cx=e.clientX-this.offsetLeft;
cy=e.clientY-this.offsetTop;}//down
o.onmousemove=function(e){
e=e||event;
if(move==true){
this.style.left=e.clientX-cx+"px";
this.style.top=e.clientY-cy+"px";}}//move
o.onmouseup=function(){
move=false;
this.innerHTML=" "}}//fn
d=document.getElementsByTagName("div").length;
drag("cont1") }//onload
</script></head>
<body><div class="cont" id="cont1"></div></body></html>
如果你想实现拖动效果,并把层拖动到当前窗口外隐藏掉的话,可以用我上面写的JS代码。如果你只是想某个窗口隐藏掉,只用CSS就可以了,方法很多,可以设置它的visibility:hidden;或者用绝对定位方法,将它的left或者top设置成负的,值它的宽度或者高度,然后给它的父元素添加CSS样式:position:relative;overflow:hidden;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-12
干嘛非要移动到屏幕的外面去呢,你直接设置为不可见不就行了??