point.js 797 B

12345678910111213141516171819202122232425262728293031
  1. function Point() {
  2. this.el = $('.item_game .points');
  3. this.classNames = ['point_1', 'point_2', 'point_3', 'point_4'];
  4. this.html = '';
  5. for(var i = 0; i < 20; i++) {
  6. this.html += this.create(i);
  7. }
  8. this.el.html(this.html);
  9. }
  10. Point.prototype = {
  11. getRandom: function(min, max) {
  12. return Math.round(Math.random() * (max - min) + min);
  13. },
  14. randomLeft: function() {
  15. return this.getRandom(260, 420);
  16. },
  17. randomIndex: function() {
  18. return this.getRandom(0, 3);
  19. },
  20. create: function(i) {
  21. var left = "left: " + this.randomLeft() + "px";
  22. var delay = "animation-delay:" + (i * 0.5).toFixed(2) + "s" ;
  23. var style = left + ";" + delay;
  24. var str = '<div class="' + this.classNames[this.randomIndex()] + '" style="' + style + '"></div>'
  25. return str;
  26. }
  27. }