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

前端 未结 5 615
礼貌的吻别
礼貌的吻别 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:22

    I know this is an old question but I ran into the same issue and found an other solution! Playing the video on click and also pause it on click. But as the original poster I ran into problems with the controls. Solved the issue with jquery like this:

    $("video").click(function (e) {
        if(e.offsetY < ($(this).height() - 36)) // Check to see if controls where clicked
        {
            if(this.paused)
                this.play();
            else
                this.pause();
        }
    });
    

    I check the offset in the click and if it is over the controls my play/pause functions doesn't do anything.

提交回复
热议问题