码迷,mamicode.com
首页 > 其他好文 > 详细

鼠标特效

时间:2019-11-07 11:32:59      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:cursor   cti   poi   margin   eve   inter   pointer   back   har   

 

方法一,代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>鼠标跟随效果</title>
<style>
body {
margin: 0;
padding: 0
}

#to_top {
width: 30px;
height: 40px;
padding: 20px;
font: 14px/20px arial;
text-align: center;
background: #06c;
position: absolute;
cursor: pointer;
color: #fff
}
</style>
<script>
window.onload = function() {
var oTop = document.getElementById("to_top");
document.onmousemove = function(event) {
var oEvent = event || window.event;
var scrollleft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
oTop.style.left = oEvent.clientX + scrollleft + 10 + "px";
oTop.style.top = oEvent.clientY + scrolltop + 10 + "px";
}
}
</script>
</head>

<body style="height:1000px;">
<a href="#">欢迎观看!</a>
<div id="to_top">鼠标跟随</div>
</body>

</html>


 

 

 

 

鼠标特效

标签:cursor   cti   poi   margin   eve   inter   pointer   back   har   

原文地址:https://www.cnblogs.com/ECJTUACM-1435867846/p/11810787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!