Heim >Web-Frontend >js-Tutorial >Dron右键菜单 v1.0_javascript技巧

Dron右键菜单 v1.0_javascript技巧

PHP中文网
PHP中文网Original
2016-05-16 19:24:40950Durchsuche

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> New Document </TITLE> 
<META NAME="Generator" CONTENT="EditPlus"> 
<META NAME="Author" CONTENT=""> 
<META NAME="Keywords" CONTENT=""> 
<META NAME="Description" CONTENT=""> 
<link rel="stylesheet" href="rm.css" type="text/css" media="all"> 
</HEAD> 

<BODY onclick="bodyclick(event)" oncontextmenu="return showcontextmenu(event)"> 
<script type="text/javascript"> 
/*******************************************\ 
  Dron右键菜单 v1.0 
  This JavaScript was writen by Dron. 
  @2003-2008 Ucren.com All rights reserved. 
  (转载或应用请保留此版权信息) 
\*******************************************/ 
var ie = (navigator.appVersion.indexOf("MSIE")!=-1);//IE 
var ff = (navigator.userAgent.indexOf("Firefox")!=-1);//Firefox 
document.write("<div id=\"rightmenu\"></div>"); 
document.write("<div id=\"rightmenubg\"></div>"); 
Array.prototype.c = Array.prototype.concat; 
function buffer() 
{ 
    var s = []; 
    s = s.c(["<a href=\"\"> 项目一</a>"]); 
    s = s.c(["<a href=\"\"> 项目二</a>"]); 
    s = s.c(["<a href=\"\"> 项目三</a>"]); 
    s = s.c(["<a href=\"\"> 项目四</a>"]); 
    s = s.c(["<a href=\"\"> 项目五</a>"]); 
    s = s.c(["<a href=\"\"> 项目六</a>"]); 
    s = s.c(["<a href=\"\"> 项目七</a>"]); 
    s = s.c(["<a href=\"\"> 项目作</a>"]); 
    s = s.join(""); 
    document.getElementById("rightmenu").innerHTML = s; 
} 
var rightmenu = document.getElementById("rightmenu"); 
var rightmenubg = document.getElementById("rightmenubg"); 
var body = document.body; 
var ex=0,ey=0; 
function showcontextmenu(evt) 
{ 
    ex = evt.clientX;ey = evt.clientY; 
    rxy(); 
    rightmenu.style.display = "block"; 
    rightmenubg.style.display = "block"; 
    evt.cancelBubble = true; 
    return false; 
} 
function bodyclick(evt) 
{ 
    rightmenu.style.display = "none";//关闭右键菜单 
    rightmenubg.style.display = "none";//关闭右键菜单 
} 
function rxy() 
{ 
    var step=3; 
    if(ie){step=1} 
    if(ff){step=6} 
    if(ex+150>body.clientWidth) 
    { 
        rightmenu.style.left = ex - 150; 
        rightmenubg.style.left = ex - 150 + step; 
    } 
    else 
    { 
        rightmenu.style.left = ex; 
        rightmenubg.style.left = ex + step; 
    } 
    if(ey+200>body.clientHeight) 
    { 
        rightmenu.style.top = ey - 160; 
        rightmenubg.style.top = ey - 160 + step; 
    } 
    else 
    { 
        rightmenu.style.top = ey; 
        rightmenubg.style.top = ey + step; 
    } 
} 
function showcontextmenu(evt) 
{ 
    ex = evt.clientX;ey = evt.clientY; 
    rxy(); 
    rightmenu.style.display = "block"; 
    rightmenubg.style.display = "block"; 
    evt.cancelBubble = true; 
    return false; 
} 
window.onload = function() 
{ 
    buffer(); 
} 
</script> 
</BODY> 
</HTML>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:渐变的Alert_javascript技巧Nächster Artikel:js传值 判断_表单特效