How can I add click-to-play to my HTML5 videos without interfering with native controls?

前端 未结 5 645
礼貌的吻别
礼貌的吻别 2021-01-04 01:49

I\'m using the following code to add click-to-play functionality to HTML5 video:

$(\'video\').click(function() {
  if ($(this).get(0).paused) {
    $(this).g         


        
5条回答
  •  旧巷少年郎
    2021-01-04 02:08

    Great answers here. Thank you for these. Here's a trick I figured out for making controls clickable, all jQuery.

    $('#video_player').click(function(e){
    
        var y = e.pageY - this.offsetTop;
    
        //Subtract how much control space you need in y-pixels.
        if(y < $(this).height() - 40) 
        {
            //$(this).get(0).play();
            //... what else?
        }
    
    });
    

提交回复
热议问题