简体   繁体   中英

How can I click svg line tag having more boundaries?

I'm every day thanks to answering developer. How can I click svg line tag having more boundaries?

This is my line tag. 在此处输入图片说明

This is I want click ling tag boundary. 在此处输入图片说明

  <body>
    <svg height="210" width="500">
      <defs>
        <filter id="f1" x="0" y="0" width="200%" height="200%">
          <feOffset result="offOut" in="SourceGraphic" dx="2" dy="2" />
          <feBlend in="SourceGraphic" in2="offOut" mode="normal" />
        </filter>
      </defs>
      <line
        x1="0"
        y1="0"
        x2="200"
        y2="200"
        style="stroke:rgb(255,0,0);stroke-width:5;box-shadow: 10px 5px 5px red;"
      ></line>
    </svg>
  </body>
  <script>
    document
      .getElementsByTagName("line")[0]
      .addEventListener("click", function(e) {
        console.log("lineClick", e);
      });
  </script>

How Can I click event boundary set more?

Add a second wider invisible line on top of the first, capture its clicks and dispatch them to the visible line underneath.

 <body> <svg height="210" width="500"> <defs> <filter id="f1" x="0" y="0" width="200%" height="200%"> <feOffset result="offOut" in="SourceGraphic" dx="2" dy="2" /> <feBlend in="SourceGraphic" in2="offOut" mode="normal" /> </filter> </defs> <line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:5;box-shadow: 10px 5px 5px red;" ></line> <line onclick="document .getElementsByTagName('line')[0].dispatchEvent(new Event('click'));" x1="0" y1="0" x2="200" y2="200" style="stroke:none;stroke-width:40;pointer-events:all;cursor:pointer" ></line> </svg> </body> <script> document .getElementsByTagName("line")[0] .addEventListener("click", function(e) { console.log("lineClick", e); }); </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM