您可以像这样创建点倾斜相机的错觉
我不确定您是否已经拥有在画布中呈现视频的代码。如果您需要知道如何在画布中显示视频,这里有一个教程:http ://html5doctor.com/video-canvas-magic/
之后,假设您有一个源为 640x480 的屏幕外图像(或视频)和一个较小的画布 320x240。
<img width=640 height=480>
<canvas width=320 height=480>
在画布中显示该图像的一小部分。
// grab a smaller part of the source and display it in the canvas
context.drawImage(source,X,Y,source.width,source.height,0,0,canvas.width,canvas.height);
然后当用户点击时,只需调整您正在显示的源的哪一部分
// change the portion of the source you’re displaying
if(mouseX<canvas.width/2 && x>0){ x-=10; }
if(mouseX>=canvas.width/2 && x<canvas.width){ x+=10; }
if(mouseY<canvas.height/2 && y>0){ y-=10; }
if(mouseY>=canvas.height/2 && y<canvas.height){ y+=10; }
这是代码和小提琴:http: //jsfiddle.net/m1erickson/3KYC5/
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
$(function(){
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var canvasOffset=$("#canvas").offset();
var offsetX=canvasOffset.left;
var offsetY=canvasOffset.top;
var img=new Image();
img.onload=function(){
draw();
}
img.src="http://dsmy2muqb7t4m.cloudfront.net/tuts/218_Trace_Face/10B.jpg";
var x=200;
var y=200;
function draw(){
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.drawImage(img,x,y,canvas.width,canvas.height,0,0,canvas.width,canvas.height);
}
function handleMouseDown(e){
mouseX=parseInt(e.clientX-offsetX);
mouseY=parseInt(e.clientY-offsetY);
// Put your mousedown stuff here
if(mouseX<canvas.width/2 && x>0){ x-=10; }
if(mouseX>=canvas.width/2 && x<canvas.width){ x+=10; }
if(mouseY<canvas.height/2 && y>0){ y-=10; }
if(mouseY>=canvas.height/2 && y<canvas.height){ y+=10; }
draw();
}
$("#canvas").mousedown(function(e){handleMouseDown(e);});
}); // end $(function(){});
</script>
</head>
<body>
<p>Click in the image to reveal in the direction of the click</p>
<canvas id="canvas" width=320 height=240></canvas>
</body>
</html>