如何获取currentTarget 的 offsetX?

        <div class="strips-Warp" @click.prevent="jumpStrips($event)" ref="stripsWarp">
            <div class="strips-play" v-bind:style="{width:playStrips + '%'}"></div>
            <div class="strips-btn" ref="stripsBtn" v-bind:style="{left:playStrips + '%'}"></div>
            <div class="strips-buffer" v-bind:style="{width:musicCache *100 + '%'}"></div>
        </div>

我需要只获取strips-Warp的 offsetX ,也就是获取currentTarget 的offsetX 。 有什么办法吗

clipboard.png

现在点击黑色会只获取到了黑色的offsetX。

阅读 4.5k
3 个回答

看下你的currentTarget是哪个dom

我简单试了下,能正常取到你想要的currentTarget啊。

<div class="strips-Warp" @click="jumpStrips($event)">
  <p>a</p>
  <p>b</p>
  <p>c</p>
</div>
new Vue({
  el: '#app',
  methods: {
    jumpStrips: function (event) {
      console.log(event.target);
      console.log(event.currentTarget);
    }
  }
});

图片描述

试下:event.currentTarget.offsetLeft

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题