implement pinch to zoom
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
<style>
|
||||
canvas {
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="../build/build.js"></script>
|
||||
|
||||
<canvas width=500 height=400></canvas>
|
||||
|
||||
<button onclick='tween.stop()'>Stop</button>
|
||||
|
||||
<script>
|
||||
var Tween = require('tween');
|
||||
var raf = require('component-raf');
|
||||
var canvas = document.querySelector('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var tween = Tween({ alpha: 0, border: 1, radius: 1 })
|
||||
.ease('out-bounce')
|
||||
.to({ alpha: 1, border: 15, radius: 150 })
|
||||
.duration(1000);
|
||||
|
||||
tween.update(function(o){
|
||||
canvas.width = canvas.width;
|
||||
ctx.strokeStyle = 'black';
|
||||
ctx.globalAlpha = o.alpha;
|
||||
ctx.lineWidth = o.border;
|
||||
ctx.arc(canvas.width / 2, canvas.height / 2, o.radius, 0, Math.PI * 2, false);
|
||||
ctx.stroke();
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
tween.on('end', function(){
|
||||
animate = function(){};
|
||||
});
|
||||
|
||||
function animate() {
|
||||
raf(animate);
|
||||
tween.update();
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
Reference in New Issue
Block a user