jQuery Dynamic Titles Plugin

Animate your browser tab’s title

jQuery Dynamic Titles changes the page title to blink, scroll, or display a constant message. A fourth action stops the effect and restores the original title.

Use it to draw attention to an update, such as a new message or a completed task. By default, effects are displayed only when the window is unfocused and stop when the user returns. Set onlyOnNonFocus: false to display an effect regardless of focus.

These basic demonstrations use onlyOnNonFocus: false so you can see them immediately. Watch this page’s browser tab after clicking a button. Each effect replaces the previous one.

Basic usage

Blink the title

Alternate between the message and the original page title.

$.dynTitles({
    type: 'blink',
    message: 'Bob says Hi',
    onlyOnNonFocus: false
});

Scroll the title

Progressively reveal the message, then scroll backward. The direction alternates by default.

$.dynTitles({
    type: 'scroll',
    message: 'Bob says Hi',
    onlyOnNonFocus: false
});

Display a constant title

Show a message without animation.

$.dynTitles({
    type: 'const',
    message: 'Bob says Hi',
    onlyOnNonFocus: false
});

Stop and restore

Stop the current effect and restore the original page title that was saved when the plugin was registered.

$.dynTitles({
    type: 'restore'
});

Installation and Source Code

To obtain and install the plugin check out:

Further instructions and source files are available on GitHub — NPM Package

Options

Options for $.dynTitles
Option Default Accepted values Description
type 'blink' 'blink', 'scroll', 'const', 'restore'

What type of title effect do you want?

Blinking 'blink', scrolling 'scroll', or display a constant/not moving 'const' title. Alternatively, use 'restore' to stop the current effect and restore the original page title that was saved when the plugin was registered.

message 'New Message' A string, including an empty string.

Text to display in the title: What message do you want to display?

Note: This option is ignored for 'restore'.

speed 'medium' 'fast', 'medium', 'slow', or a positive finite number of milliseconds up to 2147483647. Reminder: 1000 milliseconds = 1 second.

This is the delay between animation updates, i.e., the time it takes before doing the next action, such as 1 second between the text blinking or text scroll moves. Adjust this until the effect looks best for you.

Note: This option is not applicable for the 'const' or 'restore' and ignored in such cases.

direction 'fwd' 'fwd' or 'bwd'

Starting scroll direction: What direction should the message start scrolling in?

forward 'fwd' or backward 'bwd'.

Forward progressively reveals the message from its beginning; backward progressively removes characters from its beginning.

Note: This option is only applicable when the type is 'scroll'.

reverse true true or false

Should the scroll title change its direction when it gets to the end of the message, i.e. when all the message displayed going forward switch to backwards and vice-versa.

This alternating behaviour applies when 'true'. When 'false' the scroll continues in the same direction.

Note: This option is only applicable when the type is 'scroll'.

onlyOnNonFocus true true or false

Should the title only change if the window doesn't have focus i.e. your on another tab or window and you wish to notify the user something has happened on the tab containing your site, i.e a new chat message has arrived.

With true, display the effect only if the window is unfocused when called. Returning focus stops the effect and restores the saved title. Calling while focused shows the saved title without queuing an effect for a later loss of focus. With false, display regardless of focus.

Note: This option is ignored with 'restore'.

Omitted options use their defaults. Options supplied for one call do not change the defaults or carry over to subsequent calls.

Invalid applicable options throw TypeError before changing the current effect. Use actual booleans, true and false, rather than strings such as "false" or numbers such as 0 and 1. Restore ignores all effect-specific options.

Named speeds correspond to the following delays between updates:

Named speed delays
Speed Scroll delay Blink delay
'fast' 200 ms 1000 ms
'medium' 400 ms 2000 ms
'slow' 1000 ms 5000 ms

Numeric delays are used unchanged for both effects. Scrolling also uses 2000 ms pauses at the full message when reversing or starting backward, and 1500 ms pauses at the original title. Browsers may throttle timers in background tabs, so timings are approximate.

Default options

$.dynTitles.defaults = {
                            type: 'blink',
                            message: 'New Message',
                            speed: 'medium',
                            direction: 'fwd',
                            reverse: true,
                            onlyOnNonFocus: true
                        };

Examples

Blink test 1

Add a blinking message "Bob says Hi" that happens regardless of if the site is shown or not. (By default it will only happen if the tab isn't in focus as it is to alert the user to the site when they aren't looking at it). Also after the effect has started make the button say "Blink test 1 - Activated"

$.dynTitles({
                type: 'blink',
                message: 'Bob says Hi',
                onlyOnNonFocus:false
            },
            function(){
                $('#blinkBtn1').text('Blink test 1 - Activated');
            });

Try it

Scroll test 1

Same as above except this one scrolls instead of blinks. The scrolling goes forwards, backwards, forwards, backwards etc. (the default actions). Button text is updated accordingly

$.dynTitles({
                type: 'scroll',
                message: 'Bob says Hi',
                onlyOnNonFocus:false
            },
            function(){
                $('#scrollBtn1').text('Scroll test 1 - Activated');
            });

Try it

Scroll test 2

Same as above except this one only goes forward scrolling. Button text is updated accordingly

$.dynTitles({
                type: 'scroll',
                message: 'Bob says Hi',
                onlyOnNonFocus:false,
                reverse: false
            },
            function(){
                $('#scrollBtn2').text('Scroll test 2 - Activated');
            });

Try it

Scroll test 3

Same as above except this one only goes backward scrolling (the default direction is forward hence why direction didn't need to be set in the previous example). Button text is updated accordingly

$.dynTitles({
                type: 'scroll',
                message: 'Bob says Hi',
                onlyOnNonFocus:false,
                direction: 'bwd',
                reverse: false
            },
            function(){
                    $('#scrollBtn3').text('Scroll test 3 - Activated');
            });

Try it

Only On Non Focus

By default dynTitles only does the title effects when the user is not looking at the page as it is designed to alert the user to something that has happened on the page while they weren't looking at it.

To test this out you can click one of the buttons below which will set up a message to scroll or blink after 5 seconds. Therefore click the button and go onto another tab or window and see the title of this page alert you of a new message just like you might find on a chat program.

Back to Top