这段JS代码很有意思,可以在页面上写字。。。
原文来自knowsky,不过不建议看原文,原文广告太多。
原文地址为:
http://www.knowsky.com/536226.html
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>写字</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>