javascript中如何实现右键菜单(2) |
|
| 2004-05-24 enet |
| |
下面就是一个例子,感兴趣的可以把下面的拷贝成Test.html,就可以看看效果了。
< HTML>
< title>VFish Test< /title>
< script>
var x, y;
document.onmousemove=moveMouse
document.onmousedown=click
function moveMouse()
{
Layer1.style.left = event.clientX - 2;
Layer1.style.top = event.clientY - 2;
}
function click()
{
if (event.button==2)
{
x = event.clientX;
y = event.clientY;
Layer1.style.visibility="";
window.setTimeout("showMenu();", 500);
}
else
{
HiddenPop();
PopMenu.style.visibility=’hidden’;
}
}
function showMenu()
{
PopMenu.style.left = x- 2;
PopMenu.style.top = y- 2;
PopMenu.style.visibility="";
HiddenPop();
}
function HiddenPop()
{
Layer1.style.visibility=’hidden’;
}
< /script>
< BODY>
在窗口中右击一下看看出什么:)
< div id=Layer1 style="position:absolute; width:4px; height:4px; z-index:3; visibility: hidden">
< select style="width:4">< /select>
< /div>
< div id=PopMenu style="position:absolute; width:100px; height:100px; z-index:1; visibility: hidden">
< table border=2 width=100 >
< TH align="center" color="sliver" onclick="">
唯鱼的菜单
< /tH>
< tr>
< td>
click it!:)
< /td>
< /tr>
< /table>
< /div>
< /BODY>
< /HTML>
|
|
| |
|
发表评论
推荐文章
关闭窗口
|
|
|
|