javascript - Loading HTML Video With jQuery -


so trying to load different video based on screen size of device.

here jquery:

var v = new array();  v[0] = [       "header.webm",       "header.ogv",       "header.mp4"       ]; v[1] = [       "mobhead.webm",       "mobhead.ogv",       "mobhead.mp4"       ];  var src = $('#bgvid source');  if(window.innerwidth >= 642){   src.attr("src", v[0]); } if(window.innerwidth <= 641){   src.attr("src", v[1]); } 

here html:

<video autoplay="" loop="" poster="" id="bgvid">   <source src="" type="video/webm">   <source src="" type="video/ogg">   <source src="" type="video/mp4"> </video> 

here browser output:

<video autoplay="" loop="" poster="" id="bgvid">   <source src="header.webm,header.ogv,header.mp4" type="video/webm">   <source src="header.webm,header.ogv,header.mp4" type="video/ogg">   <source src="header.webm,header.ogv,header.mp4" type="video/mp4"> </video> 

you can see problem lies. need load them proper cascading order , not load them same section.

how can this?

since have jquery in project, use it:

html:

<video autoplay="" loop="" poster="" id="bgvid">   <source id="webmvid" src="" type="video/webm">   <source id="oggvid" src="" type="video/ogg">   <source id="mp4vid" src="" type="video/mp4"> </video> 

js:

var v = [];  v[0] = ["header.webm", "header.ogv", "header.mp4"]; v[1] = ["mobhead.webm", "mobhead.ogv", "mobhead.mp4"];  var index = window.innerwidth <= 641 ? 1 : 0;  $('#webmvid').attr('src', v[index][0]); $('#oggvid').attr('src', v[index][1]); $('#mp4vid').attr('src', v[index][2]); 

basically made if-case shorter , targeted each video src id , jquery.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -