JS实现控件跟随鼠标移动
2016-04-28 15:32
796 查看
显示一个div,div内显示当前的时间。
让这个div随着鼠标的移动而移动。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function mobile(){
var x = event.clientX;
var y = event.clientY;
//alert("fujichao");
document.getElementById("topid").style.left = x+"px";
document.getElementById("topid").style.top = y+"px";
}
function showTime(){
var date = new Date();
document.getElementById("topid").innerHTML= date.toLocaleString();
}
setInterval("showTime()",1000);
</script>
</head >
<body onload="showTime()" onmousemove="mobile()" style="height: 800px; width: 1000px; background-color: aquamarine;">
<div id="topid" style="border: 2px red solid;height: 200px; width: 300px;position: absolute;left: 200px; top: 200px;"></div>
</body>
</html>
让这个div随着鼠标的移动而移动。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function mobile(){
var x = event.clientX;
var y = event.clientY;
//alert("fujichao");
document.getElementById("topid").style.left = x+"px";
document.getElementById("topid").style.top = y+"px";
}
function showTime(){
var date = new Date();
document.getElementById("topid").innerHTML= date.toLocaleString();
}
setInterval("showTime()",1000);
</script>
</head >
<body onload="showTime()" onmousemove="mobile()" style="height: 800px; width: 1000px; background-color: aquamarine;">
<div id="topid" style="border: 2px red solid;height: 200px; width: 300px;position: absolute;left: 200px; top: 200px;"></div>
</body>
</html>
相关文章推荐
- [转]extjs grid的Ext.grid.CheckboxSelectionModel默认选中解决方法
- js Math对象的常用方法
- JS实现字符处理
- js Array 数组相关的方法
- JavaScript String 对象常用方法总结
- JavaScript Math 对象常用方法总结
- 用JS实现字符处理
- javascript 从ueditor中学到的闭包知识
- js 匿名函数传参
- 正则 表达式 收藏
- web Worker使js实现‘多线程’?
- Js怎么调用外部Js
- 用JS控制按钮的可用不可用
- js学习笔记
- javascript中的构造函数和继承
- JSP 基础
- 如何用QUnit为JS代码做单元测试
- js控件赋值中文乱码
- javascript中json数据添加元素
- javascript创建css、js,onload触发callback兼容主流浏览器的实现