Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

How to highlight scrolling text

Hi..
I have the following code that scrolls some text across a textbox.
How can I highlight the current word in yellow
I can't even highlight a single char with something like this

 document.getElementById('scrolling_text_box').innerHTML = text_box += "<span class='highlight'>" + x + "</span>";

Any ideas?

Here's my code

 Scroller.prototype.scroll = function () {
        var text_scroll = this.scrollText;
        var text_box = document.getElementById('scrolling_text_box').innerHTML;
        var length_scroll = text_scroll.length;
        var length_box = text_box.length;

        this.stopped = false;

        if (length_box > this.cut_text) {
            text_box = text_box.substring(1, text_box.length);
        }

        // Letter
        var x = text_scroll.substring(this.characters, this.characters + 1);

   
        text_scroll = text_box + x;
     
          document.getElementById('scrolling_text_box').innerHTML = text_scroll;

          this.characters = this.characters + 1;

        var obj = this;
        this.timer = setTimeout(function () { obj.scroll(); }, this.speed);

        if (this.characters >= length_scroll) {
            this.stopped = true;
            clearTimeout(this.timer);
        }
    }

Open in new window

Avatar of plusone3055
plusone3055
Flag of United States of America image

I may be mistaken but I was under the impression that you could not highlight a scrolling text bar. I believe the way arounds that would be to make a scrolling CSS class and place the HTML inside that DIV
ASKER CERTIFIED SOLUTION
Avatar of smeghammer
smeghammer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial