英文:
Play bg video on close Fancybox popup
问题
我已经理解您的请求。以下是代码部分的翻译:
const video = document.querySelector('.hero-section__video-bg video'),
videoPlayBtn = document.querySelector('.hero-section__video-btn')
videoPlayBtn.addEventListener('click', function () {
video.pause()
})
window.addEventListener('click', function () {
Fancybox.bind('[data-fancybox="video"]', {
on: {
close: (fancybox, eventName) => {
video.play()
},
}
})
})
英文:
I have video on bg and button for open this video in popup Fancybox
I need when I open video in Fancybox popup video on bg is paused and when I close this popup video on bg is play
I tried this code but it works on the second attempt to close the popup
Fancybox ver 5.0
const video = document.querySelector('.hero-section__video-bg video'),
videoPlayBtn = document.querySelector('.hero-section__video-btn')
videoPlayBtn.addEventListener('click', function () {
video.pause()
})
window.addEventListener('click', function () {
Fancybox.bind('[data-fancybox="video"]', {
on: {
close: (fancybox, eventName) => {
video.play()
},
}
})
})
答案1
得分: 1
我认为你不需要窗口点击处理程序。
Fancybox事件处理程序会在你点击关闭按钮时触发。
所以这会起作用。
const video = document.querySelector('.hero-section__video-bg video'),
videoPlayBtn = document.querySelector('.hero-section__video-btn')
videoPlayBtn.addEventListener('click', function() {
video.pause()
})
Fancybox.bind('[data-fancybox="video"]', {
on: {
close: (fancybox, eventName) => {
video.play()
},
}
});
英文:
I don't think you need window click handler.
Fancy box event handler will kick in when you click on close button.
So this would work.
const video = document.querySelector('.hero-section__video-bg video'),
videoPlayBtn = document.querySelector('.hero-section__video-btn')
videoPlayBtn.addEventListener('click', function() {
video.pause()
})
Fancybox.bind('[data-fancybox="video"]', {
on: {
close: (fancybox, eventName) => {
video.play()
},
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论