我需要在加载页面后5秒内自动启动函数snap。
我是怎么做到的?
完整代码原则上可以从视频文件中获取快照
<span id="snap" onclick="snap()" style="color:red">Take Screenshot</span>
<script>
var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
var w, h, ratio;
video.addEventListener('loadedmetadata', function(){
ratio = video.videoWidth / video.videoHeight;
w = video.videoWidth - 0;
h = parseInt(w / ratio, 0);
canvas.width = w;
canvas.height = h;
var a = "canvas.height";
}, false);
function snap(){
context.fillRect(0, 0, w, h);
context.drawImage(video, 0, 0, w, h);
};
</script>
答案 0 :(得分:0)
添加:
setTimeout(function(){
snap();
}, 5000);