- let treeright = document.querySelector(".treeright");
- treeright.addEventListener("contextmenu", this.rightMeun);
- this.rightMeunDefault();
- rightMeun(e) {
- e.preventDefault();
- let mymeun = document.getElementById("mymeun");
- if(this.isMeun===true){
- mymeun.style.display = "block";}
- else{
- mymeun.style.display = "none";
- }
- let X = e.pageX - 260;
- let Y = e.pageY - 3;
- mymeun.style.left = X + "px";
- mymeun.style.top = Y + "px";
- },
- rightMeunDefault() {
- let mymeun = document.getElementById("mymeun");
- window.onclick = function (event) {
- mymeun.style.display = "none";
- //如果点击菜单外的任意位置,菜单被隐藏
- };
- },
- #mymeun {
- position: absolute;
- top: 0px;
- display: none;
- border: 1px solid #dadce0;
- box-shadow: 1px 1px 2px rgb(150 141 141);
- /* background-color: red; */
- width: 100px;
- }
- <div id="mymeun">
- <div @click="newView">新增div>
- <div @click="isIcon = false">列表div>
- <div @click="isIcon = true">大图标div>
- div>
- html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>冒泡菜单title>
- <style>
- #muen {
- display: none;
- height: 100px;
- width: 50px;
- position: absolute;
- top: 0;
- left: 0;
- background-color: aliceblue;
- box-shadow: 1px 2px 5px rgb(173, 173, 173);
- }
- .all {
- height: 100vh;
- width: 100%;
- background-color: aqua;
- }
- style>
- head>
-
- <body>
- <div class="all" onclick="isMenu()">
-
- div>
- <div id="muen">
-
- <li>11li>
- <li>22li>
- <li>33li>
-
-
-
- div>
- <script>
- let all = document.querySelector(".all");
- // all.addEventListener("contextmenu", rightMeun());
- // function rightMeun(){
- // console.log("dddd");
- // }
- //this.rightMeunDefault();
- //this.initImage()
- all.oncontextmenu = function (e) {
- const muenId = document.getElementById("muen")
- muenId.style.display = "block"
- let X = e.pageX;
- let Y = e.pageY;
- muenId.style.left = X + "px";
- muenId.style.top = Y + "px";
- return false
- }
- function isMenu() {
- const muenId = document.getElementById("muen")
- muenId.style.display = "none"
- }
- window.onclick = function () {
- }
- script>
- body>
-
- html>