比如有个div层<div style="width:766px;height:10px;float:left;"></div>,这长度表示一天的时间,鼠标在这层上移动时会显示出鼠标位置的时间。这个如何实现呢,求指点!!。有类似的代码示例最好了
解决方案 »
- JQUERY UI 里的DatePicker控件 有 rangeSelect这个属性吗?
- javascript 有类似 asp select case 的语法吗?如何使用?200分悬赏
- 怎么判断鼠标左键按下后再滚动滚轮?
- 跪求!请问如何将完整网页转换文本网页?
- 如何知道一个javascript是什么类型的对象,javascript中有无类似于java的obj.getClass()方法?
- 为什么验证控件在本地上测试可以 传到服务器上就无效了????
- 就单学javascript有前途吗?
- 请问DIV的位置该怎么提取,和修改?
- 谁能把这个VBScript的代码改成JavaScript的多谢了
- IE8加载页面反应特别慢?
- 关于 层置顶问题。
- 我这里要根据时间来统计出现次数,怎么从昨天0800至今天0810怎么就出现一次呢?怎么不会时间循环?
<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">
div{
background-color:#FF6600;
width:4000px;
height:10px;
}
</style>
<script type="text/javascript">
function getPosition(obj){
var style="";
if(document.defaultView&&document.defaultView.getComputedStyle){
style=document.defaultView.getComputedStyle(obj);
}else{
style=obj.currentStyle;
}
return{
'y':style.top=="auto"?obj.offsetTop:style.top,
'x':style.left=="auto"?obj.offsetLeft:style.left
}
}
function getMousePosition(e){
var a=e||window.event;
var x=a.pageX||(a.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft));
var y=a.pageY||(a.clientY+(document.documentElement.scrollTop||document.body.scrollTop));
return {
'x':x,
'y':y
}
}
function init(){
var div=document.getElementById("test");
var div2=document.getElementById("test2");
var k=getPosition(div);
div.onmousemove=function(e){
var t=getMousePosition(e);
div2.innerHTML=t.x-k.x+":"+(t.y-k.y);
}
}
window.onload=init;
</script>
</head><body>
<div id="test"></div>
<div id="test2"></div>
</body>
</html>
类似这样试试