JavaScript mouse events, click the right mouse button, pop-up div simple instance _javascript tips

Source: Internet
Author: User

JavaScript mouse events, click the right mouse button, pop-up div simple instance

Document.oncontextmenu = function () {return false};   Disable the right mouse button menu to display
   var res = document.getElementById (' box ');   Find div
   document.body.onmouseup = function (e) {   //Click the trigger event in the body (
    e.button===2) {    // If Button=1 (left mouse button), button=2 (right mouse button), button=0 (Mouse center button)
      Console.log (e);   The parameters that are passed in are printed out
      console.log (e.offsety);   Print out the mouse click of the y-axis coordinate
      console.log (E.OFFSETX);   Print out the mouse click X axis coordinates
      res.style.top = e.offsety+ ' px ';   When the mouse clicks to the div positioning y-axis
      res.style.left = e.offsetx+ ' px ';  When the mouse clicks to the div positioning x axis
      res.style.display = ' block ';    Show Div box
    }else{
      res.style.display = ' none ';     otherwise do not show div box
    }
    
   }

Above this JavaScript mouse event, click the right mouse button, pop-up div Simple example is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.