March 27, 201412 yr On my site I have a small video playing in a loop in the top left corner, I want to click on a button and replace the video with another, then when the video has played I want to go back to the first video. There will be 7 buttons to click playing 7 videos, one at a time of cause. I'm not that savvy with Javascript to do this, I would appreciate any help on how to do this with HTML5 video. Thanks.
April 1, 201412 yr You will have to use JS. You need to use two events 1. an onclick event that triggers a function which changes the src attribute of the new video 2. use the ended event that the videoplayer returns when finished to trigger another function which resets the src attribute to the first video. http://www.w3schools.com/tags/ref_av_dom.asp EDIT: Since you have 7 buttons it might be a good idea to create the buttons as links and then target their href in your onclick function something like this: (not tested) event.preventDefault(); //prevent the browser to actually follow the links var myVideo = document.getElementById("your_video:players_id"); myVideo.setAttribute('src', this.href); myVideo.play(); Edited April 1, 201412 yr by Nillervision
Create an account or sign in to comment