您的位置:首页 > Web前端 > JavaScript

js实现文字拖动

2015-09-10 21:12 330 查看
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.move_out{position: relative;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.onmousemove=move;
	}else{
		move_out=false;
	}
}
document.onmousedown=down;
</script>
</head>
<body>
<font color="0000ff" size=10 class="move_out">万里山河,谁主沉浮</font>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: