jquery - HTML5 Video - timeupdate and scrubbing -


i have html5 video shows , plays after jquery drag , drop elements in correct slots. while video plays, have script listens timeupdate on video , changes dragged elements background color highlight , original color depending on time.

now issue when scrubbing video backwards after finished, dragged elements highlighted when code is:

function play_vid(){ $("#slots").addclass('left'); $( "#element1" ).position({my: "left top",at: "left top",of: "#slot_1"}); $( "#element2" ).position({my: "left top",at: "left top",of: "#slot_2"}); $( "#element3" ).position({my: "left top",at: "left top",of: "#slot_3"}); $( "#element4" ).position({my: "left top",at: "left top",of: "#slot_4"}); $( "#element5" ).position({my: "left top",at: "left top",of: "#slot_5"}); $(".video").show(); $("#v1").show(); v1.play(); document.getelementbyid('v1').addeventlistener("timeupdate", function() { $("#element1").removeclass('correct'); $("#element1").addclass('highlighted'); if(this.currenttime > 15) { $("#element1").removeclass('highlighted'); $("#element1").addclass('correct'); $("#element2").removeclass('correct'); $("#element2").addclass('highlighted'); }     if(this.currenttime > 30) { $("#element2").removeclass('highlighted'); $("#element2").addclass('correct'); $("#element3").removeclass('correct'); $("#element3").addclass('highlighted'); }         if(this.currenttime > 45) { $("#element3").removeclass('highlighted'); $("#element3").addclass('correct'); $("#element4").removeclass('correct'); $("#element4").addclass('highlighted'); }             if(this.currenttime > 60) { $("#element4").removeclass('highlighted'); $("#element4").addclass('correct'); $("#element5").removeclass('correct'); $("#element5").addclass('highlighted'); } }); 

how can make scrubbing video highlights elements per times above?

see fiddle @ http://jsfiddle.net/7yw59/

not sure if solution, 1 option might easier reason if have structure explicitly lists classes each element should have in timespan.

var classesattime = {     0 : { // starting @ time 0 these elements should have these classes         element1 : 'highlighted',         element2 : '',         element3 : ''     },     15 : { // starting @ time 15 ...         element1 : 'correct',         element2 : 'highlighted',         element3 : ''     },     30 : {         element1 : 'highlighted',         element2 : 'correct',         element3 : 'highlighted'     }     // ... , on }; 

while gets bit long, easy see state in @ time. in timeupdate have pick elements should have classes @ point:

document.getelementbyid('v1').addeventlistener("timeupdate", function() {     var neededclasses = {};     (var = 0; <= this.currenttime; i++) {         neededclasses = classesattime[i];     }      // go through elements     (var elementid in classesattime) {         if (!classesattime.hasownproperty(elementid)) continue;         $('#' + elementid).attr('class', neededclasses[elementid]);     } } 

if needed have more 1 class, can list them example element1 : 'highlighted foo bar'.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -