分类: 系统运维
2008-04-23 16:47:38
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript网页中写字title>
<style type="text/css">
* {
-moz-user-select:none;
border:0px;
}
#tips {
width:850px;
padding-top:8px;
padding-bottom:8px;
background:#999999;
color:#FFFFFF;
text-align:center;
margin:auto;
font-size:14px;
}
style>
<script type="text/javascript">
var Is_Mouse_Down = false
var Is_First=1
function Create(evt){
evt=evt?evt:window.event
if(Is_Mouse_Down){
if(evt.ctrlKey){
Clean(evt)
}
else {
Write(evt)
}
}
}
function Write(evt){
evt=evt?evt:window.event
var Obj_Nian=document.createElement("DIV")
Obj_Nian.style.position="absolute"
Obj_Nian.style.left=evt.clientX-10+"px"
Obj_Nian.style.top=evt.clientY-10+"px"
switch(Is_First){
case 1:Obj_Nian.innerHTML="刘";break;
case 2:Obj_Nian.innerHTML="念";break;
case 3:Obj_Nian.innerHTML="我";break;
case 4:Obj_Nian.innerHTML="喜";break;
case 5:Obj_Nian.innerHTML="欢";break;
case 6:Obj_Nian.innerHTML="你";break;
default:Obj_Nian.innerHTML="Error";break;
}
Is_First+=1
if(Is_First==7){
Is_First=1
}
Color_Nian="RGB("+Math.floor(Math.random()*100)+"%,"+Math.floor(Math.random()*100)+"%,"+Math.floor(Math.random()*100)+"%)"
Obj_Nian.style.color=Color_Nian
document.body.appendChild(Obj_Nian)
}
function Clean(evt){
evt=evt?evt:window.event
evt.srcObj=evt.srcElement?evt.srcElement:evt.target
if(evt.srcObj.tagName=="DIV" && (evt.srcObj.innerHTML=="刘" || evt.srcObj.innerHTML=="念" || evt.srcObj.innerHTML=="我" || evt.srcObj.innerHTML=="喜" || evt.srcObj.innerHTML=="欢" || evt.srcObj.innerHTML=="你")){
evt.srcObj.innerHTML=""
}
}
document.onmousedown=function(){Is_Mouse_Down=true}
document.onmousemove=Create
document.onmouseup=function(){Is_Mouse_Down=false}
script>
head>
<body onselectstart="javascript:return false">
<div id="tips">提示:按住鼠标左键不放,在页面中拖动即可写字 ; 同时按住ctrl和鼠标左键不放,在页面中拖动即可把字擦去div>
body>
html>