January 27, 2009

marquee generates swarms of scroll events in Webkit

The non-standard marquee tag, first introduced in early versions of IE, can be useful to create scrolling effects. Though deprecated, all major browsers today seem to support it.

sample scrolling text in marquee

One thing you should be aware of is that in Webkit (used by Appla Safari and Google Chrome), marquee generates a steady stream of scroll events. If you have listeners to the scroll event on the document, watch out for these events which bubble up to the document! You may want to filter out them by checking event.target. For example:

$(document).bind('scroll', function(event) {
//filter out scroll events of marquees in Webkit
if (event.target != document) return;
//documrent scroll...