javascript - 无法让 popcorn.js 工作

标签 javascript html html5-video popcornjs

我认为这是一个非常基本/愚蠢的问题,但我无法理解我做错了什么...我想使用 popcorn.js 向 html5 视频添加字幕和时间线。

这是 html5 代码:

<script src="http://popcornjs.org/code/dist/popcorn-complete.js">
</script>
(...)
<nav id="timeline"> </nav>
(...)
<video id="video" controls>
        <source src="media/ita.webm" type="video/webm">
        <source src="media/ita.mp4" type="video/mp4">
</video>
(...)

这是爆米花部分:

document.addEventListener( "DOMContentLoaded", function() {
  var popcorn = Popcorn('#video', { pauseOnLinkClicked: true });

  popcorn.timeline({
          start: 1,
          target: "timeline",
          title: "This is a title",
          text: "this is some interesting text that goes inside",
          innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
          direction: "down"
        })
        .timeline({
          start: 3,
          target: "#timeline",
          title: "double as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>",
          direction: "down"
        })
       .timeline({
          start: 7,
          end: 10,
          target: "#timeline",
          title: "3x as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "",
          direction: "down"
        });

        popcorn.subtitle({
                start: 1,
                end: 5,
                text: "Subtitle",
            });

        popcorn.play();

}, false);

pauseOnLinkClicked: true 是唯一有效的部分...

最佳答案

Here's what you've posted working in action.

在你的 JS 中你有

target: "timeline"

最初设置,但在设置之后

target: "#timeline"

时间轴数组中的下一个元素。

HTML:

<html>
    <head>
        <title>PopcornJS Test</title>
        <script src="http://popcornjs.org/code/dist/popcorn-complete.js"></script>
    </head>

    <body>
        <nav id="timeline"></nav>
        <video id="video" controls>
            <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/webm">
            <source src="media/ita.mp4" type="video/mp4">
        </video>
    </body>
</html>

JS:

document.addEventListener("DOMContentLoaded", function() {
  var popcorn = Popcorn('#video', { pauseOnLinkClicked: true });

  popcorn.timeline({
          start: 1,
          target: "timeline",
          title: "This is a title",
          text: "this is some interesting text that goes inside",
          innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
          direction: "down"
        })
        .timeline({
          start: 3,
          target: "timeline",
          title: "double as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>",
          direction: "down"
        })
       .timeline({
          start: 7,
          end: 10,
          target: "timeline",
          title: "3x as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "",
          direction: "down"
        });

        popcorn.subtitle({
            start: 1,
            end: 5,
            text: "Subtitle",
        });

        popcorn.play();

}, false);

关于javascript - 无法让 popcorn.js 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40488434/

相关文章:

javascript - 如何使用javascript在子窗口中添加脚本文件?

javascript - Node mssql : return id after SQL insertion

javascript - 如何使用 Adob​​e Air 制作 Growl 通知?

jquery - 视频背景没有占据整个 div 的宽度?

javascript - 以编程方式单击 div 根以打开使用 java 脚本在内部打开的内容

javascript - 使用 $.post() 并返回对象

javascript - 从表创建 jquery 实时预览

html - 大型 CSS 与大型 HTML

javascript - 如何生成HTML5视频音量水平图?

javascript - 双击禁用全屏?