Guest User

Untitled

a guest
Jan 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var MessageBall = Class.create();
  2. MessageBall.prototype = function () {
  3.  
  4. // private attributes
  5.  
  6. var _divTag = null;
  7. var _imgTag = null;
  8. var _size = null;
  9.  
  10. var createDiv = function(parent,id){
  11. _divTag = document.createElement("div");
  12. _divTag.id = id;
  13. _divTag.className = id;
  14. document.getElementById(parent).appendChild(_divTag);
  15. return jQuery(_divTag);
  16. }
  17.  
  18. var createBackground = function(){
  19. _imgTag = document.createElement("img");
  20. _imgTag.setAttribute("src", "img/ball.png");
  21. _imgTag.setAttribute("width","100%");
  22. _imgTag.setAttribute("height","100%");
  23. _divTag.appendChild(_imgTag);
  24. }
  25.  
  26. // public attributes
  27.  
  28. return {
  29. setSize: function(size){
  30. console.log("setSize");
  31. this.element.width(size);
  32. this.element.height(size);
  33. _size = size;
  34. },
  35.  
  36. getSize: function(){
  37. return _size;
  38. },
  39.  
  40. setPosition: function(x,y){
  41. this.element.offset({
  42. top: y-this.getSize()/2,
  43. left: x-this.getSize()/2
  44. })
  45. },
  46.  
  47. getPosition: function(){
  48. return {
  49. x:this.element.position().left+this.getSize()/2,
  50. y:this.element.position().top+this.getSize()/2
  51. }
  52. },
  53.  
  54. initialize: function(id, parent, text1, text2){
  55. console.log("MessageBall");
  56. this.element = createDiv(parent,id);
  57. createBackground();
  58. }
  59. }
  60. }();
Add Comment
Please, Sign In to add comment