javascript - jQuery element looping like a playlist under div -


i want program effect digital signage in webpage not sure how it, please kindly offer in here.

i have several div in page place holder of region. each region, there multiple media inside.

for defined duration current media play other hidden (or destroy) , subsequence media come out in same position.

most importantly, when last element reach, replay whole sequence again. webpage keep rolling.

i have made jsfiddle case, please kindly on , have spend day on on poor coding.....

https://jsfiddle.net/vx8lp9xd/11/

html

 <body>         <div class='timecontrol region1 position' >             <video duration='30' width="320" height="240" controls class='position'>               <source src="movie.mp4" type="video/mp4">             </video>             <video duration='0' width="320" height="240" controls class='position'>               <source src="movie.mp4" type="video/mp4">             </video>             </div>         <div class='timecontrol region2 position'>             <img class='position' duration='10' src='1.gif'></img>             <img class='position' duration='20' src='2.gif'></img>         </div>           <div class='readystate'></div>         </body> 

javascript

function checkcontainer () {   if($('#readystate').is(':visible')){ //if container visible on page     $('.timecontrol').each(function() {         var elements = new array();         elements = $(this).children().toarray();         (element in elements){              $(element).not(element).remove();             $(element).show();   $(element).delay(parseint($(element).attr('duration'))*1000).hide(0);             }         });          }      }            $( document ).ready(function() {             checkcontainer();     }); 

css

.position{     position:absolute; }  .region1{     position:absolute;     top:0px;     left:0px;     height:320px;     width:240px; }  .region2{     position:absolute;     top:px;     left:320px;     height:320px;     width:100px;     border:1px; } 

a recursive function (a function calls itself) better suited needs here .each() or for loop. here how recursion:

jsfiddle

function checkcontainer() {      if ($('#readystate').is(':visible')) { //if container visible on page          $('.timecontrol').each(function () {              change($(this).children());          });      }  }  function change(elements, index) {      index = !index || index > elements.length - 1 ? 0 : index; // if index higher index of last element or not set @ all, default 0        var element = $(elements[index]);      var timeframe = parseint(element.attr('duration')) * 1000;      element.siblings().hide();      element.show();      if (element[0].tagname.match(/video/i)) element[0].play();      settimeout(function () {          element.hide(0);          if (element[0].tagname.match(/video/i)) element[0].pause();          change(elements, index+1); // recursively call same functoin passing in elements , index of next 1      }, timeframe);    }  $(document).ready(function () {     checkcontainer();  });
.position {      position:absolute;  }  .region1 {      position:absolute;      top:0px;      left:0px;      height:320px;      width:240px;  }  .region2 {      position:absolute;      top:px;      left:320px;      height:320px;      width:100px;      border:1px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class='timecontrol region1 position'>      <video duration='6' width="320" height="240" controls class='position'>          <source src="http://stream.flowplayer.org/functional.mp4" type="video/mp4">      </video>      <video duration='6' width="320" height="240" controls class='position'>          <source src="http://stream.flowplayer.org/bauhaus.mp4" type="video/mp4">      </video>  </div>  <div class='timecontrol region2 position'>      <img class='position' duration='10' src='https://placeimg.com/350/150/any'></img>      <img class='position' duration='20' src='https://placeimg.com/350/150/animals'></img>  </div>  <div id='readystate'></div>


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -