这段代码什么意思,特别是封装那块

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

div{

width: 100px;

height: 100px;

background: #CCC;

position: absolute;

}

</style>

<script type="text/javascript">

function getPos(ev){

var  scrollTop=document.getElement.scrollTop||document.body.scrollTop;

var  scrolleft=document.getElement.scrolleft||document.body.scrolleft;

return{x:ev.clientX+scrollLeft,y:ev.clientY+scrollTop}

}

document.onmousemove= function(ev){

var oEvent=ev||event;

var odiv=document.getElementById("div1");

var pos=getPos(oEvent);

odiv.style.left=pos.x+"px";

   odiv.style.top=pos.y+"px";

}

</script>

</head>

<body style="height: 2000px;">

<div id="div1"></div>

</body>

</html>


Youruncle
浏览 1630回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript