javascript实现的白板效果(可以直接在网页上写字)
时间:2020-10-31 17:05:17|栏目:JavaScript代码|点击: 次
复制代码 代码如下:
<script type="text/javascript">
var ball;
var mouseX = 100;
var mouseY = 100;
var angle = 0;
var radius = 0;
function draw(){
ball = document.createElement("span");
ball.style.position = "absolute";
ball.style.color = "#FF0000";
ball.style.zIndex = 999999999;
ball.innerHTML = "●";
document.body.appendChild(ball);
ball.style["left"] = mouseX+ "px";
ball.style["top"] = mouseY+ "px";
}
function MousePos(e)
{
e = e || window.event;
var x,y;
if(!document.all){
x = e.pageX;
y = e.pageY;
}
else{
x = event.clientX + document.documentElement.scrollLeft;
y = event.clientY + document.documentElement.scrollTop;
}
return {x:x,y:y};
}
function setXY(e)
{
e = e || window.event;
var pos = MousePos(e);
mouseX = pos.x;
mouseY = pos.y;
draw();
}
window.onload = function(){
document.documentElement.onmousemove = function(e){
e = e || window.event;
setXY(e);
};
}
</script>
效果演示代码:
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
出处:http://www.cnblogs.com/airy
上一篇:cocos2dx骨骼动画Armature源码剖析(二)
栏 目:JavaScript代码
下一篇:JavaScript Math.ceil 方法(对数值向上取整)
本文标题:javascript实现的白板效果(可以直接在网页上写字)
本文地址:http://www.codeinn.net/misctech/17587.html