html5播放視頻且動(dòng)態(tài)截圖,很時(shí)尚且炫酷的一項(xiàng)功能,暫不支持chrom ,支持safari其他未測(cè)試,有需要了解的朋友可以適當(dāng)參考下
暫不支持chrom 。支持safari .其他未測(cè)試
先引用 jquery 地址。選用新浪的
代碼如下:
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.js"></script>
加一個(gè)video標(biāo)簽
代碼如下:
<video id="video" controls="controls">
<source src="1.mp4" />
</video>
然后js
代碼如下:
<script type="text/javascript">
$().ready(function(){
var video, output;
var scale = 0.25;
var initialize = function() {
output = $("#output");
video = $("#video").get(0);
$("#capture").click(captureImage);
};
var captureImage = function() {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d')
.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL();
output.prepend(img);
};
$(initialize);
});
</script>