Tip: Create a marquee to scroll text

Thursday, February 28, 2008 at 12:33 PM



Sometimes you might have more text than your gadget can display. Making that text scroll in a marquee is a great alternative to increasing the gadget's area.

The first step is to initialize a label with the text to display. You may want to add some filler text at the end to visually indicate the end of the message.
marqueeLabel.innerText = 'DEWEY DEFEATS TRUMAN; Boyle Leads in City.    ';
Then set up a timer that calls a function to shift the text:
function shiftText(label) {
label.innerText = label.innerText.substring(1) + label.innerText.charAt(0);
}

var marqueeint = view.setInterval(
'shiftText(marqueeLabel);',
200);
You can stop the marquee with this code:
view.clearInterval(marqueeint);
Have a tip you'd like to share? Send it to gd-developer AT google DOT com.

No comments: