//加上靜音屬性也播放不了
<audio
ref="audio"
preload="auto"
autoplay
src="./tip.mp3"
controls="controls"
hidden
loadedmetadata="onLoadedmetadata"
/>
</section>
<button ref="playBtn" @click="startPlay">播放</button>
//添加一個播放按鈕,正常點擊就可以播放 隱藏起來
事件:
startPlay() {
this.$refs.audio.currentTime = 0 // 從頭開始播放提示音
this.$refs.audio.play()
},
//需要觸發的時候 我的需求是輪播圖到某一張圖片的時候讓播放聲音 下面是輪播的一項配置
swiperOptionWarning: {
autoplay: { disableOnInteraction: false }, // 主要處理點擊以后不輪播的bug
loop: false,
slidesPerView: 3,
spaceBetween: 20,
speed: 800,
// 用戶操作swiper之后,是否禁止autoplay.默認為true:停止。
autoplayDisableOnInteraction: false,
// 拖動釋放時不會輸出信息,阻止click冒泡。拖動Swiper時阻止click事件。
preventLinksPropagation: true,
// 設置點擊箭頭
navigation: {
nextEl: '#next1',
prevEl: '#prev1'
}, on: {
slideChangeTransitionStart: function() {
cleartimeout()
if (_this.warningItems[this.activeIndex - 1].new) {
setTimeout(() => {
_this.$refs.playBtn.click() //定時器,這樣就行 主動書法點擊事件
})
}
}
}
},