简体   繁体   English

如何使用true / false条件在JavaScript的if循环中暂停视频?

[英]How to use a true/false condition to pause video in an if loop of javascript?

Say I get an onclick even to return either true or false and store it in a variable. 说我得到一个onclick甚至返回true或false并将其存储在变量中。

 $('.box1').on('click', function(){
            boxClicked = true;
            video1[0].play();
        });

Later on in the code, I am using; 稍后在代码中,我正在使用;

$(video1).on('timeupdate', function()
 {
       var currentTime = Math.round(this.currentTime);
       var durationNum = Math.round(this.duration);
       var formattedCurrentTime = secondsToHms(currentTime);
       var formattedDurationTime = secondsToHms(durationNum)
       onTrackedVideoFram(formattedCurrentTime, formattedDurationTime)

       if(currentTime == boxTime && boxClicked == true) { 
            video1[0].pause();
       }    
   });

});

boxTime is a variable with a prestored value of say, 10 So it should at 10 sec duration check, if the boxClick is true or false and if false , it should pause the video. boxTime是一个预存值为10的变量,因此应该在10秒的时间间隔内检查boxClicktrue还是false ,如果false ,则应该暂停视频。

My only problem... it is not doing that. 我唯一的问题是……没有这样做。

You say that you want to pause the video only when boxClicked is false . 您说仅当boxClickedfalse时才想暂停视频。 If that is the case, then simply check for boxClicked to be false rather than true in your if-statement: 如果是这种情况,则只需在if语句中检查boxClickedfalse而不是true

if(currentTime == boxTime && boxClicked == false) {
    video1[0].pause();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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