最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to stop event propagation on range input? - Stack Overflow

programmeradmin2浏览0评论

I'm coding a simple volumen slider using a range input but when the @input event fires on the range input it also fires a click event on the parent div, I've already tried all the event modifiers and none of them worked. How can I avoid that from happening?

Also, I'm aware that assigning the @click to the mute icon would be the most logical thing to do, but due to frontend decisions beyond my control, that's not an option.

<script src="@3/dist/vue.global.js"></script>

<div id="app">
  <div @click="muteVolume" id="range-test">
    <p id="volume-level">Volume: {{Math.floor(volume * 100)}}%</p>
    <input
      @input="changeVolume"
      v-model.number="volume"
      type="range"
      min="0"
      max="1"
      step="0.01"
      id="volume-slider"
    />
    <p id="mute-btn">X</p>
  </div>
</div>

<script>
  const { createApp, ref } = Vue;

  createApp({
    setup() {
      const volume = ref(0);
      const playerVolume = ref(0);
      const changeVolume = () => {
        playerVolume.value = volume.value;
      };
      const muteVolume = () => {
        volume.value = 0;
      };
      return { volume, changeVolume, muteVolume, playerVolume };
    }
  }).mount("#app");
</script>
发布评论

评论列表(0)

  1. 暂无评论