Home > Web Front-end > JS Tutorial > body text

javascript mouse right-click menu custom effect_javascript skills

WBOY
Release: 2016-05-16 15:16:27
Original
1120 people have browsed it

The example in this article explains how to implement the javascript mouse right-click menu and shares it with everyone for your reference. The specific content is as follows

Rendering:

Specific code:

<html>
  <head>
    <meta charset="gb2312" />
    <title></title>
    <style>
      #menu{
        border:solid 1px gray;
        width:100px;
        display:none;
        position:absolute;
        background-color:ghostwhite;
        margin: 0;
        padding: 0;
        list-style-type: none;
      }
      #menu>li{
        border-bottom: dashed 1px gray;
      }
    </style>
    <script type="text/javascript">
    window.onload=function(){
      var oUl=document.getElementById('menu');
        document.oncontextmenu=function(ev){
          var oEvent=ev||event;
          //一定要加px,要不然chrom不认
          oUl.style.top=oEvent.clientY+'px';
          oUl.style.left=oEvent.clientX+'px';
          oUl.style.display='block';
          return false;
        }
        document.onclick=function(){
          oUl.style.display='none';
        }
    };
    </script>
  </head>
  <body>
<ul id="menu">
  <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li>
  <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li>
  <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li>
  <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li>
</ul>
  </body>
</html>
Copy after login

I hope this article will be helpful to everyone learning JavaScript programming.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!