js鼠标事件

<html>
<script>
//鼠标按下事件
document.οnmοusedοwn=function()
{
 document.body.innerHTML="X:"+event.x+",Y"+event.y;
}
//鼠标移动事件
document.οnmοusemοve=function()
{
 document.body.innerHTML="onmousemove";
}
//鼠标松开
document.οnmοuseup=function()
{
 document.body.innerHTML="onmouseup";
}
</script>
<body>
</body>
</html>

 

<html>
<title>
</title>
<script>

//鼠标按下事件
document.οnmοusedοwn=function()
{
 document.getElementById("div1").innerHTML="X:"+event.x+",Y"+event.y;
}
//鼠标移动事件
document.οnmοusemοve=function()
{
 document.getElementById("div2").innerHTML="X:"+event.x+",Y"+event.y;
}
//鼠标松开
document.οnmοuseup=function()
{
 document.getElementById("div3").innerHTML="X:"+event.x+",Y"+event.y;
}
var run_length=10;
function run_func()
{
 var odiv=document.getElementById("div4");
 odiv.style.left=odiv.offsetLeft+run_length;
 if(odiv.offsetLeft>=800||odiv.offsetLeft<=50)
 {
  run_length=run_length*(-1);
 }
}
window.οnlοad=function()
{
 setInterval(function(){run_func();},30);
}

var obj=null;
function down_func(a)
{
 obj=a;
 ox=event.x;
 oy=event.y;
}
document.οnmοusemοve=function()
{
 if(obj!=null)
 {
  obj.style.left=obj.offsetLeft+(event.x-ox);
  obj.style.top=obj.offsetTop+(event.y-oy);
  ox=event.x;
  oy=event.y;
 }
}
document.οnmοuseup=function()
{
  obj=null;
}
</script>
<body>
<div style="background-color:gray;width:200px;height:100px;overflow:auto;" id="div1"></div>
<div style="background-color:green;width:200px;height:100px;overflow:auto;" id="div2"></div>
<div style="background-color:orange;width:200px;height:100px;overflow:auto;" id="div3"></div>
<div style="background-color:yellow;width:200px;height:100px;overflow:auto;position:absolute;top:300px;left:50px;" id="div4"></div>
<div style="background-color:red;width:50px;height:50px;overflow:auto;position:absolute;top:300px;left:50px;" id="div5" οnmοusedοwn="down_func(this);"></div>

</body>

</html>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值