简体   繁体   中英

addEventListener only triggers for first event

I am wondering why the following does work:

//maak variabelen aan
        var video = document.getElementById('video');
        var show = 100;
        var hide = 99;

    video.addEventListener("timeupdate", function() {
        if (video.currentTime >=show){
            showPlaceHolder();
        }

        if (video.currentTime <=hide){
            hidePlaceHolder();
        }
            }, false);

But for the following code only the first event triggers? :

var bvideo = document.getElementById('background');
var boombegin = 0;
var boomeind = 7;
var autoeind = 13;
var wolkbegin = 13;
var wolkeind = 19;

   bvideo.addEventListener("timeupdate", function() {
        if (bvideo.currentTime <=boombegin){
            document.getElementById('boom').style.visibility = 'visible';
            document.getElementById('wolk').style.visibility = 'hidden';
            document.getElementById('car').style.visibility = 'hidden';
        }

        if (bvideo.currentTime >=boomeind){
            document.getElementById('boom').style.visibility = 'hidden';
            document.getElementById('car').style.visibility = 'visible';
        }

        if (bvideo.currentTime >=autoeind){
            document.getElementById('car').style.visibility = 'hidden';
        }

        if (bvideo.currentTime >= wolkbegin){
            document.getElementById('wolk').style.visibility = 'visible';
        }

        if (bvideo.currentTime >= wolkeind){
            document.getElementById('wolk').style.visibility = 'hidden';
        }
    }, false);

Is there anyone who knows why only the first event is being triggered?

I have tried the following for the addEventListener: Seconds, MS, setting alerts to check which events fired (only the first one does)

I forgot to edit the following lines: from:

  if (video.currentTime >= wolkeind){

to:

if (bvideo.currentTime >= wolkeind){

so it checked for the wrong event, thanks for the advice though.

The second element seems like a slideshow, does the current time update on the 2nd one?

also your 2nd if check will always evaluate true after the second call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM