overflow-visible-event.uvue 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 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
<template>
  <view>
    <text style="font-size: 15px;">overflow=visible 点击子view(超出父view区域的部分)</text>
    <view class="backgroundview">
      <view class="box-visible-border-radius">
        <view id="child" style="width: 50px; height: 150px; background-color: greenyellow;"
          @click="handleClickOverflowPart" @touchmove="handleTouchMoveOverflowPart">
        </view>
      </view>
    </view>
  </view>
</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;
      },
      handleTouchMoveOverflowPart() {
        console.log("move");
      },
      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;
  }
</style>