Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put scrolling text in title tag?

I want to make text of title scrollable, I make the code as under it scrolls fine but the text I entered is displayed without space, meaning space in string is not considered.

<script type="text/javascript">
    //function for tittle scrolling
    function scrlsts() {
        //var scrltest = " Nature ";
        scrltest=document.title;

        //alert(scrltest);
        scrltest = scrltest.substring(1, scrltest.length) + scrltest.substring(0, 1);

        //alert(scrltest);
        document.title = scrltest;

        setTimeout("scrlsts()", 1000);
    }
    $(document).ready(function() {
        var scrltest = " Nature dff ssfd ";
        document.title=scrltest;
        scrlsts();
    });
</script> 

Thanks in advance

like image 751
Yadav Chetan Avatar asked May 03 '13 07:05

Yadav Chetan


3 Answers

Haven't made these for a long time, but this should work:

(function titleScroller(text) {
    document.title = text;
    setTimeout(function () {
        titleScroller(text.substr(1) + text.substr(0, 1));
    }, 500);
}(" Nature dff ssfd "));
like image 110
Joseph Avatar answered Sep 28 '22 02:09

Joseph


I made an easy and simple JavaScript library to accomplish this task.

like image 38
Cameron Avatar answered Sep 28 '22 04:09

Cameron


<script type='text/javascript'> 
title = "Your Title";
position = 0;
function scrolltitle() {
    document.title = title.substring(position, title.length) + title.substring(0, position); 
    position++;
    if (position > title.length) position = 0;
    titleScroll = window.setTimeout(scrolltitle,170);
}
scrolltitle();
</script>

To stop the title scroll, just run:

window.clearTimeout(titleScroll);
like image 34
Gregory R. Avatar answered Sep 28 '22 02:09

Gregory R.