Dr Paul Albinson
BSc (Hons), PGCert, MSc, PhD, MBCS, FHEA
Academic (Computing and Education) and Web Developer
Committed to professional and community engagement
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.
Alternate between the message and the original page title.
$.dynTitles({
type: 'blink',
message: 'Bob says Hi',
onlyOnNonFocus: false
});
Progressively reveal the message, then scroll backward. The direction alternates by default.
$.dynTitles({
type: 'scroll',
message: 'Bob says Hi',
onlyOnNonFocus: false
});
Show a message without animation.
$.dynTitles({
type: 'const',
message: 'Bob says Hi',
onlyOnNonFocus: false
});
Stop the current effect and restore the original page title that was saved when the plugin was registered.
$.dynTitles({
type: 'restore'
});
Further instructions and source files are available on GitHub NPM Package
| Option | Default | Accepted values | Description |
|---|---|---|---|
type |
'blink' |
'blink', 'scroll',
'const', 'restore'
|
What type of title effect do you want?
Blinking |
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 |
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 |
direction |
'fwd' |
'fwd' or 'bwd' |
Starting scroll direction: What direction should the message start scrolling in?
forward 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 |
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
Note: This option is only applicable when the type is |
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
Note: This option is ignored with |
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:
| 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.
$.dynTitles.defaults = {
type: 'blink',
message: 'New Message',
speed: 'medium',
direction: 'fwd',
reverse: true,
onlyOnNonFocus: true
};
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');
});
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');
});
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');
});
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');
});
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.