首页 > 代码库 > 文字跟随鼠标

文字跟随鼠标

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" id="txt" onkeypress="num1(this.event)">
<hr/>
<script>
function num1(obj,ev){
if(ev.keyCode<48||ev.keyCode>57)
{
ev.preventDefault();
}
}
</script>
<span id="span1">跟随我</span>
<script>
window.document.body.onmousemove=function(){
var span1=document.getElementById(‘span1‘);
span1.style.position=‘absolude‘;
span1.style.left=event.clientX+‘px‘;
span1.style.top=event.clientY+‘px‘
}


</script>
</body>
</html>

文字跟随鼠标