You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
938 B

  1. <style>
  2. canvas {
  3. border: 1px solid #eee;
  4. }
  5. </style>
  6. <script src="../build/build.js"></script>
  7. <canvas width=500 height=400></canvas>
  8. <button onclick='tween.stop()'>Stop</button>
  9. <script>
  10. var Tween = require('tween');
  11. var raf = require('component-raf');
  12. var canvas = document.querySelector('canvas');
  13. var ctx = canvas.getContext('2d');
  14. var tween = Tween({ alpha: 0, border: 1, radius: 1 })
  15. .ease('out-bounce')
  16. .to({ alpha: 1, border: 15, radius: 150 })
  17. .duration(1000);
  18. tween.update(function(o){
  19. canvas.width = canvas.width;
  20. ctx.strokeStyle = 'black';
  21. ctx.globalAlpha = o.alpha;
  22. ctx.lineWidth = o.border;
  23. ctx.arc(canvas.width / 2, canvas.height / 2, o.radius, 0, Math.PI * 2, false);
  24. ctx.stroke();
  25. ctx.fill();
  26. });
  27. tween.on('end', function(){
  28. animate = function(){};
  29. });
  30. function animate() {
  31. raf(animate);
  32. tween.update();
  33. }
  34. animate();
  35. </script>