<style>
*{margin:0;
padding:0;}
#box{
width:200px;
height:200px;
background:#f0f;
position:absolute;
left:0;top:0;
}
</style>
</head>
<body>
<div id="box"></div>
</body>
<script src="../cookie.js"></script>
<script>
var obox = document.querySelector("#box");
if(getCookie("top")){
obox.style.left = getCookie("left");
obox.style.top = getCookie("top");
}
obox.onmousedown=function(eve){
var downE=eve||window.event;
document.onmousemove=function(eve){
var e=eve||window.event;
obox.style.left = e.pageX - downE.offsetX + "px";
obox.style.top = e.pageY - downE.offsetY + "px";
}
document.onmouseup=function(){
// console.log(obox.style.left)
document.onmousemove=null;
document.onmouseup=null;
setCookie("left",obox.style.left);
setCookie("top",obox.style.top);
// obox.style.left = getCookie("left");
// obox.style.top = getCookie("top");
};
}
// setCookie("name","zhangsa")
</script>
获取窗口位置信息
最新推荐文章于 2024-07-24 03:42:19 发布