html5学习(鼠标跟随和拖拽)

温故知新,以下是我以前写的html5的案例,从电脑中翻出来了,算是知识复习和回顾吧!

有图有代码!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>html5学习(鼠标跟随和拖拽)</title>
<link rel="stylesheet" type="text/css" href="../css/inputAndDiv.css">
</head>
<body style="background-color: #CCE8CF;">
<div id="test1" style="width: 50px;height: 50px;background-color: #5F04B4;position: absolute;">
</div>
</body>
<script type="text/javascript">
//鼠标跟随
var divNode = document.getElementById("test1");
divNode.onmousedown = function() {
	document.onmousemove = function(ev) {
// 		console.log(ev);
// 		console.log(divNode);
		divNode.style.left = ev.clientX + "px";
		divNode.style.top = ev.clientY + "px";
	}
}
</script>
</html>

完!

猜你喜欢

转载自blog.csdn.net/czh500/article/details/111773834