-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change video via javascript #22
Comments
Hello @Porco-Rosso, The JS itself will just run the video when it's ready to play, debounce resize event, and add a class that actually alters the video(s). Did you load the required css file? |
Yes I added the css, and the default video works. Sorry if this out of scope for the project! Though a function to change the background video would be a cool addition. |
Hello, Thank you for the attachment. It's an interesting find. You can find that out like this (simply pasting in browser console will do the trick): You could check const vdgElement = document.querySelector('#vidage')
const srcType = vdgElement.currentSrc.slice(vdgElement.currentSrc.lastIndexOf('.') + 1)
switch (srcType) {
case 'webm':
vdgElement.src = 'path_to_webm_file_source'
break
case 'mp4':
vdgElement.src = 'path_to_mp4_file_source'
break
} By that logic, everything should work as normal, but it's too much mess and logic IMO. Another suggestion, which I'd prefer, is to use given vidage element and load the source again when you generate sources dynamically. It'd look something like this in your example: randomVideo(); // I capitalized V in Video
const vdg = new Vidage('#vidage')
vdg.element.load()
|
Thanks! I went with your second suggestion and works perfectly now. Thanks for teaching me a little bit. |
Hi, just trying to pick a random video from an array on each load but it doesn't seem to work.
it shows the link is changed in the html elements viewer, but does not actually alter the video. Am I missing something?
The text was updated successfully, but these errors were encountered: