首页 > 代码库 > 事件基础
事件基础
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> div { width: 20px; height: 20px; background-color: red; position: absolute; } </style> <script type="text/javascript"> function getPosition(ev) { var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; return { x: ev.clientX + scrollLeft, y: ev.clientY + scrollTop } } window.onload = function () { document.onmousemove = function (ev) { var arrDiv = document.getElementsByTagName("div"); var oEvent = ev || event; var pos = getPosition(oEvent); for (var i = arrDiv.length - 1; i > 0; i--) { arrDiv[i].style.left = arrDiv[i - 1].offsetLeft + "px"; arrDiv[i].style.top = arrDiv[i - 1].offsetTop + "px"; } arrDiv[0].style.left = pos.x + "px"; arrDiv[0].style.top = pos.y + "px"; } } </script></head><body> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div></body></html>
事件基础
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。