<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030" />
<title>Untitled Document</title>
</head>
<script>
function show()
{
var obj = document.getElementById("a")
obj.style.display="block";
obj.style.pixelTop = event.clientY;
obj.style.pixelLeft = event.clientX;
}
document.onmousedown = show;
</script>
<body>
<div id="a" style=" position:absolute;background:#CCCCCC; width:300px; height:200px; display:none;"></div>
</body>
</html>
当点击到窗口的右边缘时,屏幕会敞开.且出现滚动条.如何解决这个问题啊?
在线等.........
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030" />
<title>Untitled Document</title>
</head>
<script>
function show()
{
var obj = document.getElementById("a")
obj.style.display="block";
obj.style.pixelTop = event.clientY;
obj.style.pixelLeft = event.clientX;
}
document.onmousedown = show;
</script>
<body>
<div id="a" style=" position:absolute;background:#CCCCCC; width:300px; height:200px; display:none;"></div>
</body>
</html>
当点击到窗口的右边缘时,屏幕会敞开.且出现滚动条.如何解决这个问题啊?
在线等.........
<div id="a" style=" position:absolute;background:#CCCCCC; width:300px; height:200px; display:none;"> </div>
</div>你用JS计算是否超出框,超出多少就向左移动多少就不会被隐藏,另外,你的代码只可以在IE执行...最好考虑兼容
先判断一下onmousedown 点击的位置(坐标),然后再做显示处理。
如果撑开的话,就让它显示在左上方。
希望对你有所帮助
obj.style.pixelLeft = event.clientX;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
The pixelTop property reflects the value of the Cascading Style Sheets (CSS) top attribute. Use the offsetTop property to calculate actual positions within the document area.
Unlike the top property, the pixelTop value is an integer, not a string, and is always interpreted in pixels.
Because the value of the top property is a string, you cannot use the property in script to calculate the position of the object in the document; instead, use the pixelTop or the posTop property.
你这块DIV=>A是可移动的,当你鼠标点击右边时,A的左上方坐标就是鼠标的坐标,那肯定会出现A的宽可能走出当前页面范围了,所以出现滚动条了.
obj.style.Top = event.clientY-A的高;
obj.style.Left = event.clientX-A的宽;
但点左边时,又会出现它向左,所以要进行判断位置了.
obj.style.Top=event.clientX 有没有超出屏幕的宽.如果超出,就进行处理,减去它的宽,
高也这样判断了.
这是我的答案,希望有帮助.