index.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>vue.js version</title>
  5. <script src="https://cdn.jsdelivr.net/stats.js/r11/stats.min.js"></script>
  6. <script src="../../dist/vue.js"></script>
  7. <style>
  8. html, body {
  9. height: 100%;
  10. width: 100%;
  11. padding: 0;
  12. margin: 0;
  13. }
  14. svg {
  15. width: 800px;
  16. height: 600px;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="app">
  22. <svg>
  23. <circle v-for='point in points' :cx='point.x' :cy='point.y' r='2px' fill='#FC309D'></circle>
  24. </svg>
  25. </div>
  26. <script type="text/javascript" charset="utf-8">
  27. var stats = new Stats();
  28. stats.setMode(0); // 0: fps, 1: ms, 2: mb
  29. // align top-left
  30. stats.domElement.style.position = 'absolute';
  31. stats.domElement.style.left = '0px';
  32. stats.domElement.style.top = '0px';
  33. document.body.appendChild( stats.domElement );
  34. var WIDTH = 800
  35. var HEIGHT = 600
  36. var model = createModel(1000);
  37. new Vue({
  38. el: '#app',
  39. data: model,
  40. created: function () {
  41. var self = this
  42. self.raf = window.requestAnimationFrame(render)
  43. stats.begin()
  44. function render () {
  45. stats.end()
  46. stats.begin()
  47. self.raf = window.requestAnimationFrame(render)
  48. self.step()
  49. }
  50. }
  51. });
  52. function createModel (count) {
  53. var points = []
  54. for (var i = 0; i < count; ++i) {
  55. points.push({
  56. x: Math.random() * WIDTH,
  57. y: Math.random() * HEIGHT,
  58. vx: Math.random() * 4 - 2,
  59. vy: Math.random() * 4 - 2
  60. })
  61. }
  62. return {
  63. points: points,
  64. step: step
  65. }
  66. function step () {
  67. points.forEach(move)
  68. // move(points[0])
  69. }
  70. function move (p) {
  71. if (p.x > WIDTH || p.x < 0) p.vx *= -1
  72. if (p.y > HEIGHT || p.y < 0) p.vy *= -1
  73. p.y += p.vy
  74. p.x += p.vx
  75. }
  76. }
  77. </script>
  78. </body>
  79. </html>