Editing Marquee Canvas This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <!DOCTYPE HTML> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> // inner variables var marquee, context; var dir = 1; //1 is left, -1 is right :) var speed = 10; //higher is faster var fontsize = "120px"; //font size as per CSS rules var fontfamily = "Arial"; //font family as per CSS rules var fontweight = "normal"; //font weight as per CSS rules var fontcolor = "#000"; //Font colour as per CSS rules //Now get ready to draw text var font = fontweight+" "+fontsize+" "+fontfamily; //font style as per CSS rules var mx; var text; var textlength; function draw() { marquee.width = marquee.width; //simplest way to clear a canvas frame context.fillStyle = fontcolor; context.font = font; context.textBaseline = "middle"; context.fillText(text, mx, marquee.height / 2); //draw the text in the specified style mx -= dir; //move in the specified direction by 1. textlength = context.measureText(text); //this gives a pixel length of the text string if (mx < 0 - textlength.width) //Text has scrolled off the left hand side; restart it. { mx = marquee.width; } else if (mx > marquee.width) //Text has scrolled off the right hand side; restart it. { mx = 0 - textlength.width; } } </script> </head> <body> <canvas id="marqueeCanvas" width="1025" height="70">TRASA: WAWRZYSZEW-STARE</canvas> </body> </html> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) marquee draw text Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code marquee = document.getElementById('marqueeCanvas'); context = marquee.getContext("2d"); speed = 100; font = 'italic bold 65px/0px Arial, Helvetica, sans-serif'; text = marquee.innerHTML; mx = marquee.width; Test 2 Title Async (check if this is an asynchronous test) Code setInterval(draw, 1000 / (speed * 10));