網站視頻嵌入很常見,但通常缺乏互動性。 popcorn.js將嵌入式視頻提升為完全沉浸式體驗,將視頻播放與動態網頁元素同步。本教程演示瞭如何。
> popcorn.js的關鍵好處:
html結構:
創建index.html
<div>
包括popcorn.js:<pre class="brush:php;toolbar:false"><code class="language-html"><!DOCTYPE html>
<title>Hello World Popcorn.js</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<style>
.video, #map {
width: 300px;
height: 200px;
float: left;
}
</style>
<div class="video"></div>
</code></pre>添加popcorn.js庫到您的html <ol start="2">:<li>>
<strong>
</strong>
<code>
<code class="language-html"> </code>):
app.js
記住要通過YouTube Player功能的HTTP服務器(例如,MacOS上的app.js
<code class="language-javascript">window.onload = function() { var pop = Popcorn.youtube(".video", "http://www.youtube.com/watch?v=x88Z5txBc7w"); pop.play(); };</code>>讓我們增強基於視頻時間戳動態更新內容的應用程序。 我們將顯示Yakko的世界視頻中提到的國家名稱。
python -m SimpleHTTPServer 2723
添加文本元素:添加元素以顯示
>中的國家名稱:
<h2></h2>
插件操作:index.html
使用<code class="language-html"><h2>Yakko's singing about <span class="country-name"></span> </h2></code>>在特定時間戳上更新
code()
code()
> app.js
圖像與<h2></h2>
插件的集成:<code class="language-javascript">// ... (previous code) ... var countries = [ { start: 20.2, end: 20.7, country_name: "United States" }, // ... add more countries ... ]; countries.forEach(function(country) { pop.code({ start: country.start, end: country.end, onStart: function() { document.querySelector(".country-name").innerHTML = country.country_name; } }); }); // ... (rest of the code) ...</code>>。 修改
flickr()
<div id="photos"></div>
index.html
app.js
集成Google地圖:flickr()
包括<code class="language-javascript">// ... (previous code) ... countries.forEach(function(country) { // ... (code plugin) ... pop.flickr({ start: country.start, end: country.end, tags: country.country_name + " Flag", numberofimages: 5, height: "100px", width: "100px", target: "photos" }); }); // ... (rest of the code) ...</code>
index.html
index.html <code>index.html
。 在 app.js<code>app.js
中,初始化地圖並使用地理編碼器根據國家名稱定位標記:
<code class="language-html"><!DOCTYPE html> <title>Hello World Popcorn.js</title> <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> <style> .video, #map { width: 300px; height: 200px; float: left; } </style> <div class="video"></div> </code>
這個擴展的示例在創建動態,交互式視頻體驗時顯示了popcorn.js的多功能性。 請記住,請諮詢官方的popcorn.js文檔以獲取更多詳細信息和插件選項。
>以上是用popcorn.js創建豐富的視頻體驗的詳細內容。更多資訊請關注PHP中文網其他相關文章!