<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript event兼容问题及ev.clientX左距离,ev.clientY上距离,及onmousemove移动事件</title>
<style>
#div1 {
width:100px; height:100px; background-color:#72C39C; position:absolute
}
</style>
<script>
window.onload = function(){
var oDiv = document.getElementById('div1');
document.onmousemove = function(ev){
//event兼容性问题
var ev = ev || event;
//scrollTop兼容性处理
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
oDiv.style.left = ev.clientX + 'px';
oDiv.style.top = ev.clientY + scrollTop + 'px';
//alert(ev.clientY);
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
JavaScript event兼容问题及ev.clientX左距离,ev.clientY上距离,及onmousemove移动事件
最新推荐文章于 2022-10-17 10:30:00 发布