How to target autoplay attribute in HTML 5 Video element inside modal

后端 未结 4 654
一生所求
一生所求 2021-01-23 23:35

I have a HTML 5 video element inside a modal window. Now I need a check that if modal is opened and video element has autoplay then play the video. If the video does not have th

4条回答
  •  被撕碎了的回忆
    2021-01-23 23:52

    You're using the variable autoplay rather than the string "autoplay", try updating your code to this:

    if ($('.modal-box.opened').find('video').attr('autoplay') == true) {
      console.log('CLICK: ModalBox if Video Autoplay is true.');
    }
    

    UPDATE:

    Try this instead:

    if (($('.modal-box.opened').find('video').attr('autoplay') === 'autoplay')) {
      $('.modal-box.opened').find('video').get(0).play();
    }
    

提交回复
热议问题