快應用tabs和video組件滑動事件優先級問題

快應用tabs和video組件滑動事件優先級問題java

現象描述:

tabs子組件tab-content內容是video組件組成的,左右滑動切換tabs內容時,偶爾會不切換而是拖動視頻進度條。app

問題代碼以下:

<template>
  <div style="background-color: #00bfff;">
    <tabs index="0" >
      <tab-bar mode="fixed">
      </tab-bar>
      <tab-content>
        <div  style="flex-direction: column;">
          <text style="color: red">1</text>
          <stack class="video" >
            <video class="video1" id="111" 
              src="https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/cae-legoup-video-target/93be3d88-9fc2-4fbd-bd14-833bca731ca7.mp4">
              </video>
          </stack>
        </div>

        <div  style="flex-direction: column;">
          <text style="color: red">2</text>
        </div>

        <div style="flex-direction: column;">
          <text style="color: red">3</text>
        </div>
      </tab-content>
    </tabs>
  </div>
</template>

問題分析:

video組件是tabs的子組件,video組件和tabs組件都是自帶滑動能力,此問題關鍵在於滑動的地方在video區域上,根據事件從裏層往外層的冒泡機制,系統會優先處理video的滑動,而不是tabs的切換,而video的滑動效果就是咱們看到的調整了視頻播放進度。ide

解決方案:

在video區域上覆蓋一層div(video父節點stack增長子節點div),注意div的高低要小於video的高度,保證video底部的進度條、播放按鈕區域不被遮擋。當在video區域滑動時,其實是在div上,因爲div和video是兄弟節點,不會觸發video的滑動事件,完美解決了以上問題。flex

實現代碼以下(見紅色部分):

<template>
  <div style="background-color: #00bfff;">
    <tabs index="0" >
      <tab-bar mode="fixed">
      </tab-bar>
      <tab-content>
        <div  style="flex-direction: column;">
          <text style="color: red">1</text>
          <stack class="video">
            <video class="video1" id="111" 
              src="https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/cae-legoup-video-target/93be3d88-9fc2-4fbd-bd14-833bca731ca7.mp4"
              onstart="start" ontouchmove="move" onseeked="seeked">
              </video>
              <div style="width: 100%;height:300px;" onclick="bof">
               </div>
          </stack>
        </div>

        <div  style="flex-direction: column;">
          <text style="color: red">2</text>
        </div>

        <div style="flex-direction: column;">
          <text style="color: red">3</text>
        </div>

      </tab-content>
    </tabs>
  </div>
</template>

欲瞭解更多詳情,請參閱:ui

快應用tabs組件:3d

https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-stylecode

快應用video組件:component

https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-component-video視頻


原文連接:https://developer.huawei.com/consumer/cn/forum/topic/0204404990358220225?fid=18事件

原做者:Mayism

相關文章
相關標籤/搜索