<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
} html,
body {
height: 100%;
overflow: hidden;
} #box {
position: absolute;
width: 150px;
height: 150px;
background-color: orangered;
}
</style>
</head> <body>
略略略
<div id="box"></div> <script>
window.onload = function () {
var box = document.getElementById("box"); box.onmousedown = function (e) {
e = e || window.event;
var mouseDownPoint = { "x": 0, "y": 0 };
var boxStartPoint = { "x": 0, "y": 0 }; boxStartPoint.x = this.offsetLeft;
boxStartPoint.y = this.offsetTop; mouseDownPoint.x = e.clientX;
mouseDownPoint.y = e.clientY; // 使用全局捕获,阻止ie8以下浏览器事件的默认行为
if (this.setCapture) {
this.setCapture();
} document.onmousemove = function (e) { e = e || window.event;
var mouseMovePoint = { "x": 0, "y": 0 }; mouseMovePoint.x = e.clientX;
mouseMovePoint.y = e.clientY; box.style.left = mouseMovePoint.x - mouseDownPoint.x + boxStartPoint.x + "px";
box.style.top = mouseMovePoint.y - mouseDownPoint.y + boxStartPoint.y + "px"; return false; // 无法禁止ie8以下浏览器事件的默认行为
} document.onmouseup = function () {
document.onmousemove = document.onmouseup = null; if (document.releaseCapture) { // 取消全局捕获
document.releaseCapture();
} }
}
}
</script>
</body> </html>

兼容ie8,使用全局捕获,阻止ie8以下浏览器事件的默认行为

最新文章

  1. MVC4 学习备忘
  2. BI 项目管理之生命周期跟踪和任务区域
  3. [HDOJ5783]Divide the Sequence(贪心)
  4. centos 下安装.net core
  5. React History
  6. python关键字
  7. Hadoop-2.2.0中文文档—— Common - CLI MiniCluster
  8. AngularJS 基础教程二:
  9. zabbix 布署实践【2 agent安装】
  10. typescript解决深度拷贝中循环引用引起的死循环
  11. input file实现多选和限制文件上传类型
  12. Python-接口自动化(九)
  13. WPF 开源项目
  14. JS高级-原型等概念深入理解
  15. HashMap与TreeMap按照key和value排序
  16. swift杂记
  17. db2错误代码大全
  18. leetcode第一刷_Combinations
  19. [leetcode]523. Continuous Subarray Sum连续子数组和(为K的倍数)
  20. html5 audio vedio and video.js

热门文章

  1. 了解IHttpModule接口事件执行顺便 获取Session
  2. jq 合并json对象
  3. 使用SLF4J和LOGBACK (一 : 基本使用)
  4. HTTP Get与Post请求
  5. nfs之脚气
  6. XStream使用笔记
  7. 实例演示oracle数据块状态视图v$bh的用法二 热点块问题(转)
  8. kafka 高可靠
  9. Linux系统构架 - HA集群配置
  10. vertex shader(3)