Lấy tọa độ của con trỏ(mouse) 2007-09-18 02:02:35
Xác định tọa độ (x,y) của mouse trên màn hình:<br />
Demo: Di chuyển chuột và nhìn lên title của trình duyệt<br />
<script language="JavaScript">
var firefox=document.getElementById&&!document.all;
document.onmousemove=mouseMove;
function mouseMove(e){
var str;
if (firefox) str="x="+e.clientX+", y="+e.clientY;
else str="x="+event.clientX+", y="+event.clientY;
document.title=str;
}
</script>
Code:
Demo: Di chuyển chuột và nhìn lên title của trình duyệt<br />
<script language="JavaScript">
var firefox=document.getElementById&&!document.all;
document.onmousemove=mouseMove;
function mouseMove(e){
var str;
if (firefox) str="x="+e.clientX+", y="+e.clientY;
else str="x="+event.clientX+", y="+event.clientY;
document.title=str;
}
</script>
Code:
<script language="JavaScript">
var firefox=document.getElementById&&!document.all;
document.onmousemove=mouseMove;
function mouseMove(e){
var str;
if (firefox) str="x="+e.clientX+", y="+e.clientY;
else str="x="+event.clientX+", y="+event.clientY;
document.title=str;
}
</script>
var firefox=document.getElementById&&!document.all;
document.onmousemove=mouseMove;
function mouseMove(e){
var str;
if (firefox) str="x="+e.clientX+", y="+e.clientY;
else str="x="+event.clientX+", y="+event.clientY;
document.title=str;
}
</script>
Tra loi 6 comment(s) 2007-09-18 02:02:35
minhbu 2007-11-11 10:32:49
Tra loi
NguyenDien_Cafe 2008-05-10 04:22:40
# IdDiv{position: absolute; visibility:hidden}
Sao khi có sự kiện chuột bên trên thì dùng hàm Javascript xử lý:
Cho id.style.left=e.clientX; id.style.top=e.clientY; và
id.style.visibility="visible";
Đây chỉ là mô hình thôi, còn bạn nên viết chi tiết ra, chúc may mắn
Tra loi
mvtuyen 2009-01-22 07:22:46
Tra loi
Kenzero 2010-01-31 08:43:48
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body{ position:relative;}
div#dhtmltooltip{ position:absolute; left:0px; top:0px; border:1px solid #999; padding:10px; height:auto;}
</style>
<script language="JavaScript">
function mouseMove(e){
// Chieu dai cua khung tooltip
width = 100;
document.getElementById("dhtmltooltip").style.width = width + "px";
// Kiem tra trinh duyet va lay ra toa do cua chuot
var firefox = document.getElementById && !document.all;
var str;
if (firefox){
x = e.clientX; y = e.clientY;
}
else{
x = event.clientX; y = event.clientY;
}
//
if(x > screen.width - width - 50){
x = x - width - 40;
y = y + 15;
if(y > screen.height/2){
document.getElementById("dhtmltooltip").style.top = y - 100 + "px";
}
else{
document.getElementById("dhtmltooltip").style.top = y + 15 + "px";
}
}
else{
if(y > screen.height/2){
document.getElementById("dhtmltooltip").style.top = y - 100 + "px";
}
else{
document.getElementById("dhtmltooltip").style.top = y + 15 + "px";
}
}
document.getElementById("dhtmltooltip").style.left = x + "px";
}
document.onmousemove = mouseMove;
</script>
</head>
<body>
<div id="dhtmltooltip">
Kenzero<br>
Kenzero<br>
Kenzero<br>
</div>
</body>
</html>
Tra loi
hai lua 2010-04-25 11:13:49
cam on
Tra loi
TG 2010-04-26 09:12:07
Tra loi
Y kien