地图上的div的点击穿透

该代码示例展示了如何在HTML/CSS/JavaScript环境中利用BaiduMapsWebGLAPI创建地图,并通过pointer-events属性控制元素的点击交互。通过将pointer-events设为auto或none,可以实现特定区域的点击事件响应。页面包含一个顶部工具栏,其按钮具有点击触发alert的功能。
摘要由CSDN通过智能技术生成
直接查看 关键的一点是:pointer-events: auto;
<!DOCTYPE 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">
  <script src="//api.map.baidu.com/api?v=1.0&&type=webgl&ak=p07Q22uzDZR0jBnTIIbfy7ukOUBRlQhr"></script>
  <title>Map Demo</title>
  <style>
    html{height:100%}    
    body{height:100%;margin:0px;padding:0px}    
    #container{height:100%}

    .top-tool-wrapper {
      position: absolute;
      box-sizing: border-box;
      top: 24px;
      width: 100%;
      height: 40px;
      display: flex;
      padding: 0 24px;
      z-index: 99;
      /* background-color: red; */
      pointer-events: none;
    }
    
    .top-tool-wrapper .button {
      pointer-events: auto;
      height: 40px;
      line-height: 40px;
      cursor: pointer;
      padding: 0 24px;
      background-color: #409EFF;
      color: #fff;
      box-shadow: 0 2px 4px 0 rgba(0,0,0,.12);
      border-radius: 4px;
      user-select:none;
    }

    .top-tool-wrapper .button:hover {
      background-color: #53a8fc;
    }
    .top-tool-wrapper .button+.button {
      margin-left: 16px;
    }
    .flex-spacer {
      flex: 1;
    }
  </style>
</head>
<body>
  <div id="container"></div>

  <div class="top-tool-wrapper">
    <div class="button" onclick="alert('test')">test</div>
    <div class="button" onclick="alert('test')">test</div>
    <div class="button" onclick="alert('test')">test</div>
    <div class="button" onclick="alert('test')">test</div>
    <div class="button" onclick="alert('test')">test</div>
    <div class="flex-spacer"></div>
    <div class="button" onclick="alert('test')">test</div>
  </div>

  <script>
    var map = new BMapGL.Map("container");
    map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
      map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
  </script>
</body>
</html>
此处的可以直接粘贴 查看效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_2524963996

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值