You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a simple Video component and I want to automatically play/stop the video depending on slide visibility.
Using the code below, I was able to make it work. Though this is not clean (as relying on a class name attribute that can theoretically change anytime), so I was wondering if there was a better way to detect slide visibility from inside a custom component?
import{ref,watchEffect,getCurrentInstance}from'vue'import{useMediaControls}from'@vueuse/core'constvm=getCurrentInstance()constvideo=ref()const{ playing, currentTime }=useMediaControls(video)watchEffect(()=>{constcomponentRouteName=vm.parent.attrs.class.replace('slidev-','')constcurrentRouteName=vm.ctx.$slidev.nav.route.nameif(componentRouteName===currentRouteName){console.log('Slide is visible, playing video.')currentTime.value=0playing.value=true}else{console.log('Slide is invisible, stopping video.')playing.value=false}})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have created a simple Video component and I want to automatically play/stop the video depending on slide visibility.
Using the code below, I was able to make it work. Though this is not clean (as relying on a class name attribute that can theoretically change anytime), so I was wondering if there was a better way to detect slide visibility from inside a custom component?
Beta Was this translation helpful? Give feedback.
All reactions