- | Afiseaza codul
function Scroller(canvas, scrollingText, speed, textColor) { this.canvas = canvas; this.text = scrollingText; this.textWidth = 0; this.textHeight = 12; this.rate = speed; this.textColor = textColor; this.showText = true; this.font = "12px Arial"; var self = this; this.animId; this.xloc = 0; this.yloc = 0; this.yloc2 = 50; this.yloc3 = 100; this.yloc4 = 150; this.yloc5 = 200; this.yloc6 = 250; this.yloc7 = 300; this.yloc8 = 350; this.doAnimation = function() { this.animId = requestAnimationFrame(function() { self.doAnimation(); }); if(this.textWidth == 0) { var context = this.canvas.getContext("2d"); context.font = this.font; this.textWidth = context.measureText(this.text).width; } if(this.yloc > this.canvas.height + this.textHeight) { this.yloc = 0; } else { this.yloc += this.rate; } if(this.yloc2 > this.canvas.height + this.textHeight) { this.yloc2 = 0; } else { this.yloc2 += this.rate; } if(this.yloc3 > this.canvas.height + this.textHeight) { this.yloc3 = 0; } else { this.yloc3 += this.rate; } if(this.yloc4 > this.canvas.height + this.textHeight) { this.yloc4 = 0; } else { this.yloc4 += this.rate; } if(this.yloc5 > this.canvas.height + this.textHeight) { this.yloc5 = 0; } else { this.yloc5 += this.rate; } if(this.yloc6 > this.canvas.height + this.textHeight) { this.yloc6 = 0; } else { this.yloc6 += this.rate; } if(this.yloc7 > this.canvas.height + this.textHeight) { this.yloc7 = 0; } else { this.yloc7 += this.rate; } if(this.yloc8 > this.canvas.height + this.textHeight) { this.yloc8 = 0; } else { this.yloc8 += this.rate; } this.drawText(); } this.drawText = function() { var context = this.canvas.getContext("2d"); context.clearRect(0, 0, this.canvas.width, this.canvas.height); if(this.showText) { context.font = this.font; context.fillStyle = this.textColor; context.fillText(this.text, this.xloc, this.yloc); context.fillText(this.text, this.xloc, this.yloc2); context.fillText(this.text, this.xloc, this.yloc3); context.fillText(this.text, this.xloc, this.yloc4); context.fillText(this.text, this.xloc, this.yloc5); context.fillText(this.text, this.xloc, this.yloc6); context.fillText(this.text, this.xloc, this.yloc7); context.fillText(this.text, this.xloc, this.yloc8); } }; }
Are cineva o idee?