• 【无标题】右键菜单


    1. let treeright = document.querySelector(".treeright");
    2. treeright.addEventListener("contextmenu", this.rightMeun);
    3. this.rightMeunDefault();
    1. rightMeun(e) {
    2. e.preventDefault();
    3. let mymeun = document.getElementById("mymeun");
    4. if(this.isMeun===true){
    5. mymeun.style.display = "block";}
    6. else{
    7. mymeun.style.display = "none";
    8. }
    9. let X = e.pageX - 260;
    10. let Y = e.pageY - 3;
    11. mymeun.style.left = X + "px";
    12. mymeun.style.top = Y + "px";
    13. },
    14. rightMeunDefault() {
    15. let mymeun = document.getElementById("mymeun");
    16. window.onclick = function (event) {
    17. mymeun.style.display = "none";
    18. //如果点击菜单外的任意位置,菜单被隐藏
    19. };
    20. },
    1. #mymeun {
    2. position: absolute;
    3. top: 0px;
    4. display: none;
    5. border: 1px solid #dadce0;
    6. box-shadow: 1px 1px 2px rgb(150 141 141);
    7. /* background-color: red; */
    8. width: 100px;
    9. }
    1. <div id="mymeun">
    2. <div @click="newView">新增div>
    3. <div @click="isIcon = false">列表div>
    4. <div @click="isIcon = true">大图标div>
    5. div>
    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>冒泡菜单title>
    8. <style>
    9. #muen {
    10. display: none;
    11. height: 100px;
    12. width: 50px;
    13. position: absolute;
    14. top: 0;
    15. left: 0;
    16. background-color: aliceblue;
    17. box-shadow: 1px 2px 5px rgb(173, 173, 173);
    18. }
    19. .all {
    20. height: 100vh;
    21. width: 100%;
    22. background-color: aqua;
    23. }
    24. style>
    25. head>
    26. <body>
    27. <div class="all" onclick="isMenu()">
    28. div>
    29. <div id="muen">
    30. <li>11li>
    31. <li>22li>
    32. <li>33li>
    33. div>
    34. <script>
    35. let all = document.querySelector(".all");
    36. // all.addEventListener("contextmenu", rightMeun());
    37. // function rightMeun(){
    38. // console.log("dddd");
    39. // }
    40. //this.rightMeunDefault();
    41. //this.initImage()
    42. all.oncontextmenu = function (e) {
    43. const muenId = document.getElementById("muen")
    44. muenId.style.display = "block"
    45. let X = e.pageX;
    46. let Y = e.pageY;
    47. muenId.style.left = X + "px";
    48. muenId.style.top = Y + "px";
    49. return false
    50. }
    51. function isMenu() {
    52. const muenId = document.getElementById("muen")
    53. muenId.style.display = "none"
    54. }
    55. window.onclick = function () {
    56. }
    57. script>
    58. body>
    59. html>

  • 相关阅读:
    linux安装aerospike免安装版
    java计算机毕业设计基于node.js的疫情大数据展示与政策查询系统
    使用PowerShell脚本来一键开启、关闭FTP服务
    <stl系列>,vector深度剖析,掌握stl容器从这篇文章开始
    Dash应用页面整体布局技巧
    【数据结构】Set和Map
    fabic.js Quadratic Curve /可控制的曲线
    java虚拟机详解篇二(类字节码详解)
    Undo Log、Redo Log、binlog与两阶段提交
    java毕业设计商场会员管理系统源码+lw文档+mybatis+系统+mysql数据库+调试
  • 原文地址:https://blog.csdn.net/qq_51389137/article/details/125594603