Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MessageBall = Class.create();
- MessageBall.prototype = function () {
- // private attributes
- var _divTag = null;
- var _imgTag = null;
- var _size = null;
- var createDiv = function(parent,id){
- _divTag = document.createElement("div");
- _divTag.id = id;
- _divTag.className = id;
- document.getElementById(parent).appendChild(_divTag);
- return jQuery(_divTag);
- }
- var createBackground = function(){
- _imgTag = document.createElement("img");
- _imgTag.setAttribute("src", "img/ball.png");
- _imgTag.setAttribute("width","100%");
- _imgTag.setAttribute("height","100%");
- _divTag.appendChild(_imgTag);
- }
- // public attributes
- return {
- setSize: function(size){
- console.log("setSize");
- this.element.width(size);
- this.element.height(size);
- _size = size;
- },
- getSize: function(){
- return _size;
- },
- setPosition: function(x,y){
- this.element.offset({
- top: y-this.getSize()/2,
- left: x-this.getSize()/2
- })
- },
- getPosition: function(){
- return {
- x:this.element.position().left+this.getSize()/2,
- y:this.element.position().top+this.getSize()/2
- }
- },
- initialize: function(id, parent, text1, text2){
- console.log("MessageBall");
- this.element = createDiv(parent,id);
- createBackground();
- }
- }
- }();
Add Comment
Please, Sign In to add comment