简体   繁体   中英

HTML5 video only play if play button is clicked, not surrounding area

When clicking on a video, a details view should open within a popup. This happens with no issue via my drawEditForm() function, but it also begins playing the video (even if the play button wasn't clicked but an area of the video was). Is there a way that I can dictate that the video should only play if the play button is clicked and not the surrounding area of the video?

        <div class="thumbDiv" onclick="asset.drawEditForm('2081833185')">
            <video controls="controls" preload="metadata">
                <source src="assets/myvideo.mp4#t=0.1" type="video/mp4">
            </video>        
        </div>

Try using preventDefault() :

document.querySelector('.video').addEventListener('click', function () {
  event.preventDefault();
});

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