<!DOCTYPE html>
<html>
<head>
<title>函数的简单调用</title>
<meta charset="utf-8">
<style type="text/css">
html,body{
width: 100%;
height: 100%;
}
.move_out{
position: absolute;
cursor: hand;
font-family: "华文行楷";
} </style>
<script type="text/javascript">
var move_out = false;
var z,x,y;
function move(){
if (event.button==move_out) {
z.style.pixelLeft=temporarily1+event.clientX-x;
z.style.pixelTop=temporarily2+event.clientY-y;
return false;
}
}
function down(){
if (event.srcElement.className == "move_out") {
move_out=true;
z=event.srcElement;
temporarily1 =z.style.pixelLeft;
temporarily2 =z.style.pixelTop;
x = event.clientX;
y = event.clientY;
document.onmousedown=move;
}else{
move_out=false;
}
}
document.onmousedown = down;
</script>
</head>
<body >
<font class="move_out">文字跟随鼠标移动</font>
</body>
</html>
<html>
<head>
<title>函数的简单调用</title>
<meta charset="utf-8">
<style type="text/css">
html,body{
width: 100%;
height: 100%;
}
.move_out{
position: absolute;
cursor: hand;
font-family: "华文行楷";
} </style>
<script type="text/javascript">
var move_out = false;
var z,x,y;
function move(){
if (event.button==move_out) {
z.style.pixelLeft=temporarily1+event.clientX-x;
z.style.pixelTop=temporarily2+event.clientY-y;
return false;
}
}
function down(){
if (event.srcElement.className == "move_out") {
move_out=true;
z=event.srcElement;
temporarily1 =z.style.pixelLeft;
temporarily2 =z.style.pixelTop;
x = event.clientX;
y = event.clientY;
document.onmousedown=move;
}else{
move_out=false;
}
}
document.onmousedown = down;
</script>
</head>
<body >
<font class="move_out">文字跟随鼠标移动</font>
</body>
</html>
if (event.srcElement.className == "move_out") {
move_out=true;
z=event.srcElement;
temporarily1 =z.style.pixelLeft;
temporarily2 =z.style.pixelTop;
x = event.clientX;
y = event.clientY;
document.onmousemove=move;
}else{
move_out=false;
}
}
<!DOCTYPE html>
<html>
<head>
<title>函数的简单调用</title>
<meta charset="utf-8">
<style type="text/css">
html,body{
width: 100%;
height: 100%;
}
.move_out{
position: absolute;
cursor: hand;
font-family: "华文行楷";
}</style>
<script type="text/javascript">
function down(){
document.onmousemove=DivFlying;
}
function DivFlying() {
var div = document.getElementById("test");
if (!div) {
return;
}
div.style.left = window.event.clientX + "px";
div.style.top = window.event.clientY + "px";
}
//document.onmousedown = down;
document.onmousemove=DivFlying;
</script>
</head>
<body>
<font id="test" class="move_out">文字跟随鼠标移动</font>
</body>
</html>
话说,这真是书上写的吗?你这代码太不严谨了。还是不行没有反应
书太老了,这代码只能在IE9以前的浏览器中运行,IE11和其它浏览器不行