overflow-visible-event.uvue 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<template>
  <view>
    <text style="font-size: 15px;">overflow=visible 父view(绿色),子view(红色),点击超出父view区域的部分也可触发事件。</text>
    <view class="backgroundview">
      <view class="box-visible-border-radius">
        <view id="child" style="width: 50px; height: 150px; background-color: red;"
          @click="handleClickOverflowPart" @touchmove="handleTouchMoveOverflowPart">
        </view>
      </view>
    </view>
雪洛's avatar
雪洛 已提交
11
  </view>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
</template>

<script>
  export default {
    data() {
      return {
        jest_result: false,
        jest_click_x: -1,
        jest_click_y: -1
      }
    },
    methods: {
      handleClickOverflowPart() {
        console.log("click");
        this.jest_result = true;
        uni.showToast({"title":"点击红色区域"})
      },
      handleTouchMoveOverflowPart(e:UniTouchEvent) {
        console.log("touchmove:" + e.touches[0].clientX + "," + e.touches[0].clientY);
      },
      handleClick(str : string) {
        console.log(`点击了 ${str} view`);
        if (str == 'red') {
          this.jest_result = true;
        }
      },
      jest_getRect() {
        const rect = uni.getElementById('child')?.getBoundingClientRect()
        if (rect != null) {
          const ratio = uni.getSystemInfoSync().devicePixelRatio
          this.jest_click_x = rect.x * ratio + 10
          this.jest_click_y = rect.bottom * ratio - 10
        }
      }
    }
  }
</script>

<style>
  .backgroundview {
    width: 300px;
    height: 300px;
    margin-bottom: 20px;
    background-color: white;
    justify-content: center;
    align-items: center;
  }

  .box-visible-border-radius {
    width: 100px;
    height: 100px;
    border-radius: 20px;
    overflow: visible;
    background-color: green;
  }

68 69
  .hover-class {
    background-color: aqua;
70
  }
71
</style>