代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
html{
height: 100%;
}
body{
/*height: calc(100% - 16px);*/
margin:0;
height: 100%;
}
#main{
width: 100px;
height:100px;
background-color: red;
position:absolute;
}
</style>
</head>
<body>
<div id="main"></div>
</body>
<script src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
drag();
function drag() {
var odrag = document.getElementById("main");
odrag.onmousedown = function(ev) {
var oevent = ev || event;
var distanceX = oevent.clientX - odrag.offsetLeft;
var distanceY = oevent.clientY - odrag.offsetTop;
var old_x = oevent.clientX;
var old_y = oevent.clientY;
document.onmousemove = function(ev) {
var oevent = ev || event;
var _x, _y;
_x = oevent.clientX - distanceX;
_y = oevent.clientY - distanceY;
if (_x < 0) _x = 0;
if (_y < 0) _y = 0;
if (_x > document.body.clientWidth - odrag.offsetWidth) _x = document.body.clientWidth - odrag.offsetWidth;
if (_y > document.body.clientHeight - odrag.offsetHeight) _y = document.body.clientHeight - odrag.offsetHeight;
odrag.style.left = _x + 'px';
odrag.style.top = _y + 'px';
};
document.onmouseup = function(ev) {
var oevent = ev || event;
var _x = oevent.clientX - distanceX;
var _y = oevent.clientY - distanceY;
var leftindex = (_x / $("body").width()).toFixed(2);
var topindex = (_y / $("body").height()).toFixed(2);
//存储位置区域比列或者具体数据
document.onmousemove = null;
document.onmouseup = null;
};
}
}
</script>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。