javascript - Playing a video when clicking on an element of an image. -


i want know if it's possible play video when click on element of image, , play video if click on element of same image ?

for instance, imagine picture of room : - if click on area tv set is, image disappears , video1 starts. - if click on chair, same thing video2 starts instead.

is possible using html5 , javascript? if so, how going ?

thanks lot reading !

yes, possible.

i'm assuming have basic understanding of html , javascript. work on browsers have support html5 , video element specifically.

first, add video element page

<video id="video" width="600">   <source type="video/mp4">   browser not support html5 video. </video> 

then let's assume have 2 images, video 1 , video 2

<img src="tv.png" id="video1btn" onclick="loadvideo1()" value="load video 1" /> <img src="chair.png" id="video2btn" onclick="loadvideo2()" value="load video 2" /> 

once button clicked javascript function in onclick attribute called.

function loadvideo1() {  var videoel = document.getelementsbytagname('video')[0];  var sourceel = videoel.getelementsbytagname('source')[0];  sourceel.src = 'video1.mp4';  videoel.load(); }  function loadvideo2() {  var videoel = document.getelementsbytagname('video')[0];  var sourceel = videoel.getelementsbytagname('source')[0];  sourceel.src = 'video2.mp4';  videoel.load(); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -