Javascript Parser错误 [英] Javascript Parser error

查看:160
本文介绍了Javascript Parser错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML5视频,其中包含海报和CSS播放覆盖按钮。我试图让视频在结束后加载,以便再次显示海报和播放覆盖按钮。

I have a HTML5 video that has a poster and a CSS play overlay button. I am trying to get the video to load once it has ended so that it shows the poster and the play overlay button again.

我尝试了下面的代码但得到了最后一行有分析器错误,任何人都可以帮助我,让我知道它是做错了什么!?

I have tried the following code but get a Parser error on the last line, can anybody help me and let me know what it is I am doing wrong!?

$(document).ready(function() {
  $('.video').parent().click(function () {
    if ($(this).children(".video").get(0).paused) {
      $(this).children(".video").get(0).play();
      $(this).children(".playpause").fadeOut();
    } else {
      $(this).children(".video").get(0).pause();
      $(this).children(".playpause").fadeIn();
    }
  });

  var video= $(".video").get(0);   
  video.addEventListener('ended',function () {
    video.load(); 
    $(".playpause").show();                              
  }, false);
});


推荐答案

预防

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

错误,如果<$ code> 语句 c $ c>在 setTimeout()调用中单击处理程序。

error, wrap if statement within click handler within setTimeout() call.

另见如何防止play()请求被对pause()的调用中断错误?

$(document).ready(function() {
  $('.video').parent().click(function () {
    var vid = $(this).children(".video").get(0);
    setTimeout(function() {
    if (vid.paused) {
      vid.play();
      $(this).children(".playpause").fadeOut();
    } else {
      vid.pause();
      $(this).children(".playpause").fadeIn();
    }
    })
  });

  var video= $(".video").get(0);   
  video.addEventListener('ended',function () {
    video.load(); 
    $(".playpause").show();                              
  }, false);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
click<br>
<span class="playpause">play pause</span>
<video controls class="video" poster="https://placehold.it/350x150"  src="https://nickdesaulniers.github.io/netfix/demo/frag_bunny.mp4"></video>
</div>

这篇关于Javascript Parser错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆