1.

  1. <template>
  2. <div res="box" @click="action($event,123)"></div>
  3. </template>

2.

  1. action(e,index){
  2. let boxWidth = this.$refs.box.clientWidth // box的宽度
  3. let screenLeft = e.pageX // 鼠标距离屏幕左侧的距离
  4. let boxLeft = this.$refs.box.getBoundingClientRect().left // box距离屏幕左侧的距离
  5. let overHalf = (screenLeft - boxLeft) > boxWidth / 2 // 鼠标位置是否超过了容器的一半
  6. }
作者 铁血 汉子 2021年8月13日
2025/06/21/05:10:45am 2021/8/13/11:55:39
0 1026