好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 用HTML5制作視頻拼圖的教程

用HTML5制作視頻拼圖的教程

熱門標簽:南通數據外呼系統推廣 申請400電話流程簡介 阜陽企業外呼系統 地圖標注位置能賺錢嗎 呼和浩特外呼電銷系統排名 pageadm實現地圖標注 外呼線穩定線路 邢臺縣地圖標注app 外呼系統電話怎么投訴

幾天前同事給我看了一個特效,是一個拼圖游戲,不同的是,拼圖里的是動畫。他讓我看下做個DEMO,于是就自己整了一會,也確實不難。用canvas很容易做。所以這篇博文不適合高手看。。。。就是隨便寫來玩玩的。
效果圖:

至少我剛看到這個的時候覺得挺新穎的,所以才會想到做出來玩玩,覺得樓主out的哥們請輕噴

  不多說,先上DEMO:視頻拼圖  (或許要等一會才能看到效果,我是直接在w3school那里搞了個視頻鏈接過來的,拖動什么的都做的很簡單,或許還有些bug,畢竟就只是做一個DEMO玩玩而已,說說原理就行了),還有一點,直接把視頻的當前幀畫到canvas中在移動設備上好像還不支持。。。至少我用ipad看了一下,發現畫不上去,如果有知道腫么解決這問題的大牛請為小弟解答一下,不甚感激

  原理:每一塊拼圖就是一個canvas,同時還需要一個離屏canvas。先整一個video標簽


復制代碼
代碼如下:
</p> <p><video id="video" src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4" width="600px" height="400px" controls="control" loop="loop" style="display:block;position:absolute;top:-6000px;"></video></p> <p>

并且把video隱藏掉,然后播放視頻的時候把每一幀都畫到離屏canvas中(離屏canvas就是隱藏了的canvas,用于保存數據),寫法很簡單:


復制代碼
代碼如下:
ctx.drawImage(video , 0 , 0 , vw , vh);

,直接用drawImage方法畫上去就行了。為何要先用離屏canvas呢,因為如果直接把每一幀數據同時畫到所有拼圖塊的canvas中,瀏覽器會瞬間崩掉。所以用一個離屏canvas作為緩沖。先把當前幀的數據保存到canvas,然后再將canvas畫到作為拼圖塊的canvas中。將canvas畫到canvas中也很簡單,也是用drawImage就可以搞定:

ctx2.drawImage(cs , -this.cols*this.w , -this.rows*this.h , vw , vh);

然后。。。。原理就這么簡單,之后提醒一點,用requestAnimationFrame循環取幀時,要限一下速,例如下面所寫的,我是每30毫秒取一次,推薦30~50毫秒,太低瀏覽器容易崩潰,太高的話視頻出現卡幀現象了:

 

復制代碼
代碼如下:

function animate(){
var newTime = new Date();
if(newTime - lastTime > 30){
lastTime = newTime;
ctx.drawImage(video , 0 , 0 , vw , vh);
canvases.forEach(function(){
var ctx2 = this.cas.getContext('2d');
ctx2.drawImage(cs , -this.cols*this.w , -this.rows*this.h , vw , vh);
});
}
if("requestAnimationFrame" in window){
requestAnimationFrame(animate);
}
else if("webkitRequestAnimationFrame" in window){
webkitRequestAnimationFrame(animate);
}
else if("msRequestAnimationFrame" in window){
msRequestAnimationFrame(animate);
}
else if("mozRequestAnimationFrame" in window){
mozRequestAnimationFrame(animate);
}
}


最后貼出所有代碼: 
復制代碼
代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<style>
body{margin:0;padding:0;}
.allCanvas{
position: relative;
margin:50px auto;
width:600px;
}
.vcanvas{
position: absolute;
display: block;
border: 1px solid;
}
</style>
<title>視頻拼圖</title>
</head>
<body>
<div class="allCanvas">
<canvas id="liping" width="600" height="400" style="display:none"></canvas>
</div>
<video id="video" src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4" width="600px" height="400px" controls="control" loop="loop" style="display:block;position:absolute;top:-6000px;"></video>
<script>
var video = document.getElementById("video");
var cs = document.getElementById("liping");
var ctx = cs.getContext('2d')
var rows = 3,
cols = 3,
cb = document.querySelector(".allCanvas"),
vw = 600,
vh = 400,
canvases = [];</p> <p> function createCanvas(){
var num = rows*cols;
for(var i=0;i<cols;i++){
for(var j=0;j<rows;j++){
var canvas = new vCanvas(Math.random()*600, Math.random()*600 , vw/rows , vh/cols , j , i);
canvases.push(canvas);
}
}
}</p> <p> var vCanvas = function(x,y,w,h,cols,rows){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.cols = cols;
this.rows = rows;
this.creat();
this.behavior();
}
vCanvas.prototype = {
creat:function(){
this.cas = document.createElement("canvas");
cb.appendChild(this.cas);
this.cas.className = "vcanvas";
this.cas.id = "vc_"+(this.cols+1)*(this.rows+1);
this.cas.style.left = this.x+"px";
this.cas.style.top = this.y+"px";
this.cas.width = this.w;
this.cas.height = this.h;
},
behavior:function(){
this.cas.onmousedown = function(e){
e = e || window.event;
var that = this;
var om = {
x:e.clientX,
y:e.clientY
}
window.onmousemove = function(e){
e = e || window.event;
var nm = {
x:e.clientX,
y:e.clientY
}
that.style.left = parseInt(that.style.left.replace("px","")) + (nm.x-om.x) + "px";
that.style.top = parseInt(that.style.top.replace("px","")) + (nm.y-om.y) + "px";
om = nm;
}
window.onmouseup = function(){
this.onmousemove = null;
}
}
}
}</p> <p> Array.prototype.forEach = function(callback){
for(var i=0;i<this.length;i++){
callback.call(this[i]);
}
}</p> <p> var lastTime = 0;
function initAnimate(){
lastTime = new Date();
createCanvas();
animate();
}</p> <p> function animate(){
var newTime = new Date();
if(newTime - lastTime > 30){
lastTime = newTime;
ctx.drawImage(video , 0 , 0 , vw , vh);
canvases.forEach(function(){
var ctx2 = this.cas.getContext('2d');
ctx2.drawImage(cs , -this.cols*this.w , -this.rows*this.h , vw , vh);
});
}
if("requestAnimationFrame" in window){
requestAnimationFrame(animate);
}
else if("webkitRequestAnimationFrame" in window){
webkitRequestAnimationFrame(animate);
}
else if("msRequestAnimationFrame" in window){
msRequestAnimationFrame(animate);
}
else if("mozRequestAnimationFrame" in window){
mozRequestAnimationFrame(animate);
}
}</p> <p> video.play();
initAnimate();
</script>
</body>
</html>

標簽:楊凌 鶴崗 黃山 撫順 德州 蚌埠 內蒙古 辛集

巨人網絡通訊聲明:本文標題《用HTML5制作視頻拼圖的教程》,本文關鍵詞  用,HTML5,制作,視頻,拼圖,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《用HTML5制作視頻拼圖的教程》相關的同類信息!
  • 本頁收集關于用HTML5制作視頻拼圖的教程的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 征服艳岳爽| 精品国产人妻AV多野结衣| 武则天艳史婬片第二集免费放| 欧美IPHONEXSMAX| 美女被?到爽??高潮草莓动漫| 亚洲国产熟女一区二区三区胖妞 | 国产精品欧美日韩| 锕锕锕锕锕锕锕锕好痛| 男女爱爱好爽全过程| 性一交一乱一色一视频麻豆| 女人私密全部露出来| 2019国产夜间视频| vodafonewifi粗暴| 傻子变聪明继续睡女| 小芳好湿?好紧?好多水高潮| 女人被躁到高潮嗷嗷叫| 欧美一级婬片a毛片无码| 兄长的权限| 成+人+黄+色有声+小说免费| 国产片婬乱一级毛片| 朴妮唛36集无删减版视频| 日韩国产片| 中文字幕人妻丝袜成熟乱九区| 大学生初次破苞免费视频| 在线亚洲国产一区欧美-色猫AV| 全黄h全肉撅起屁股挨打| 国产伦精品一区二区三区视频金莲| 国产又大又黑又粗免费视频| 人狗合体| 印度大肥妞bbwbbw| 古代肉文| 狠痕鲁| 亚精产品一二三三三早餐店| 亚洲精品23p熟女35P| 老司机黄色网| 欧美一区二区三区久久久久久久久| 免费?无码?国产在线19男男| 999精品视频在线观看热6| 欧美日韩激情一区二区三区| 校花调教喷水沦为肉奴| 骚虎视频|