
Attention, Effect, EyeCandy, Fade, Fading, Graphics, Refresh, Update, YellowFadeTechnique
Tracy's checking out her portfolio, which shows each stock in its own row. Suddenly, "Neverland Mining Co." stock plummets, and the row lights up to reflect the change. Tracy's attention is drawn instantly by this visual effect, and she immediately begins to offload her stake in the company.
To ensure the user's working with current data, the browser display must be frequently updated.
With Ajax, it's possible to update only the portion of the screen that changed. And, if nothing has changed, the display will remain exactly as is.
The screen can get cluttered with a lot of information, much of which might be changing at any time.
While human vision is good at spotting changes, it's easy to miss a sudden change, especially if it's a subtle one.
When a display element undergoes a value change - or any other significant change - dynamically increase its brightness for a second or so. As a device for communicating system activity, the One-Second Spotlight accomplishes several things:
That an event has occurred is made explicit, as opposed to the user having to actively monitor for changes, and trying to remember what - if anything - has changed.
Because the spotlight lasts for a few seconds, the user has enough time to redirect attention to the item and study the details of the event, such as look at an item's new value. In contrast, a standard transition would afford no time whatsoever - if the user happened to blink, they could easily miss the change.
When the animation technique follows certain conventions or mimics real-world phenomena, it can provide hints to the user about the nature of the event.
This pattern is a generalisation of the technique 37Signals introduced as The Yellow Fade Technique. There, an item lights up for a second after the user has edited it, and the lighting quickly fades away. Unlike a conventional application, where a page refresh would occur, it's often not clear when an “XMLHttpRequest Call” has occurred. So a quick visual effect is almost essential for the user to understand what's happening.
From a technical perspective, the Yellow Fade Technique is usually achieved by suddenly switching the element's background colour style from white to yellow, then using “Scheduling” to run through a continuous spectrum of background colours, starting with yellow and ending with white.
In more general terms, One-Second Spotlight encompasses several types of animation. One or more of the following CSS styles are affected during the spotlight period:
color - Usually, it is the element's background that changes, but font colour is also a possibility. Though commonly assigned with Red-Green-Blue hex codes such as "#ff00ff", animation algorithms can benefit from the percentage form, e.g. " (100%, 0%, 100%). Often, the algorithm cycles through one or more of the Red, Green, and Blue components, e.g. gradually raise Red from 50% to 100% and back to 50%, while holding blue and green constant. You might also prefer to represent the colour as a combination of Hue-Saturation-Value (HSV), and cycle through one or more of those components. In which case, calculate the HSV values and convert them to RGB for display.
opacity - how transparent the element is; an opacity of zero means the item is solid, and an opacity of 50% means the browser background - or any items underneath the element - will be partially visible.
visibility - whether the element can be seen. Visibility does not affect page layout, so the element still occupies the same space on the page.
The possibilities are endless, but there are a few common effects. First, there are straightforward transitions from one style setting to another:
Fade Out - An element suddenly brightens, and then fades back to its original appearance. Useful for general highlighting, and may also indicate its been "sucked into" the server, i.e. the data is now safely stored server-side. Since many pages use a white background, fading the background out to white is a natural choice for general attention-grabbing.
Fade In - An element is suddenly dimmed, and then brightens up to its original appearance. Useful for general highlighting, and may also indicate its been "pushed out" of the server.
Fade Away - An element fades further and further out until it disappears altogether. If the element is already somewhat dim, it may be helpful to brighten it at the start of the animation. This effect often indicates the element (or its value) has been suspended or destroyed.
Materialise - From nothing, an element fades into its regular appearance. If its regular appearance is somewhat dim, it may be helpful to fade it in to a higher level, then fade back out a bit. This can indicate that the element has been created or retrieved.
Switch - Element gradually switches appearance from one setting to another. Instead of fading or brightening, though, an element might shift from red to blue. This effect usually is used to indicate a state change.
The other category of effects involves rapid oscillation:
Total Flash - In rapid succession, an element completely disappears, and then appears again. The transition to and from a state of disappearance can be achieved by continuous fading, or by simply toggling the visibility style. This effect is useful as a general attention grabber, although it brings back memories of the dreaded <blink> tag; be sparing in your use of flashing elements.
Shifting Flash - An element's appearance shifts several times from one setting to another. This can also be used as a general attention grabber if the element returns back to its original appearance. If the element permanently shifts from one setting to another, this effect will grab attention more effectively than Switch, which is a more subtle transition.
A typical implementation combines “Display Morphing” with “Scheduling”. To fade an item out, for instance, the following algorithm may be used:
Remember the element's current setting.
Set element.style.color to a bright setting.
Every 100 milliseconds:
Fade the element a bit. More precisely, drop color by 10% (of the bright setting). This applies individually to each color component (R,G,B).
Check if 1000 milliseconds has already passed. If so, set the element back to its original setting (it should already be about that anyway).
The algorithm is based on interpolation. In moving from color A to color B, there are a number of discrete transitions that occur, say once every 100 milliseconds. At each stage, the algorithm decides where - along the spectrum from A to B - the colour should be. Since a colour consists of three components - R, G, and B - the calculation occurs separately for each component.
So, let's say we're shifting from #ffffff to #000044. First, its useful to represent these as decimal percentage settings: (100%, 100%, 100%) moving to (0%, 0%, 25%). And assume we're going to make ten transitions. The red and green components will shift down 10% each step, and the blue component will shift down 7.5% each time. So it's just a matter of dropping the value for each color component at each transition, rounding off, and redisplaying the element.
If you want to make a transition to the background of the element, you can instead shift opacity instead of colour. (Be aware there are portability issues with opacity.)
The algorithm assumes a linear interpolation, where each transition drops by the same amount. You could also experiment with other transitions. An exponentially increasing interval, for example, would give an effect of an initially slow transition, leading to a quick burst at the end. A similar phenomenon is quite common with flash effects, where the flashing starts off slowly and speeds up at the end.
You probably won't have to hand-code many of these effects, because libraries like scriptaculous (discussed below) are quite flexible and easy to incorporate.
An Ajax App undergoes multiple events; which warrant a spotlight? A spotlight can serve any of the following purposes:
Draw the user's attention to a change.
Suggest the user needs to do something.
Inform the user a browser-server interaction has taken place.
Inform the user that another user has done something.
Examples:
The user has just changed something. A Fade Out effect suggests the change has been sent to the server.
On the server, a new item has been created. A Materialise effect suggests the item has just appeared.
The user has forgotten to enter a form field. The field undergoes a Shifting Flash as its background shifts from white to red.
An item has just changed value. A Fade Out effect suggests the change was just picked up by the browser.
Popularised by 37Signals, yellow is becoming something of a standard for fading effects. In general, though, the colour has to take into consideration which element is affected, as well as surrounding elements and the page appearance in general.
Additionally, multiple colours can be used to good effect. For instance, each colour can be used to represent a different type of event. In a multi-user context, JotSpot Live illustrates how each user can be associated with a different colour, so their recent edits appear as distinctly-coloured fade effects.
Asking how long the spotlight lasts might seem a bit ridiculous for a pattern named "One-Second Spotlight". But the name, of course, only hints at one reasonable value. You'll have to decide on the precise duration of the overall effect and also how many transitions will take place in that time.
Considerations:
A longer duration will have a greater window of time to be noticed.
A longer duration will appear less dramatic, so might be interpreted as a less critical event.
A longer duration increases the likelihood of multiple spotlights occurring simultaneously, which might be confusing, especially if they are flash effects.
A longer duration also increases the likelihood of a second spotlight effect occurring on the same element, while the first effect is in progress. That's not necessarily a problem in itself, but does lead to an implementation issue; it's worth ensuring an element is only undergoing one effect at a time to prevent any nasty technical issues.
As far as transitions go, the trade-off is fairly clear: faster transitions will look smoother, but slow down the application. Is the user likely to leave your application in a background tab and only check it once an hour? If so, avoid slowing down the whole browser with high-granularity effects. Likewise if the application is already process-intensive.
This is an area where different browsers will act differently. For instance, what's the lowest possible transition time you can set? That will depend on the user's system and the browser in question. You can experiment with different parameters on the Time Spotlight Demo.
37Signals Backpack maintains items in a list (Figure 1.81, “Backpack”). When you click the Edit button, the read-only item morphs into a textarea. On saving, it becomes read-only again, and is accompanied by a yellow Fade Out effect. All quite fitting for the company that coined the term, "Yellow Fade Technique".
chat.app shows text messages as you or other people enter them. Each new message is highlighted with a yellow Fade Out.
Digg Spy shows new stories as they appear on the web. Each time a block of new stories appear, they appear with a Fade Out effect, with the background shifting from grey to white.
Coloir is a slideshow application. Each time you click next, an animated "loading" icon appears, and a new photo fades in.
Odeo is a podcast subscription service. You can force Odeo to grab the latest feed for a podcast, and during the delay, the entire document fades. An effect like this can be achieved with a partially-transparent “Popup” element covering the whole document. It feels similar to the way Windows fades the entire screen when you're about to log out.
Scriptaculous is an excellent Javascript library, supporting many Ajax UI patterns. Its visual effects library is based on four fundamental effects:
Altering opacity
Altering scale
Altering position
"Parallel" effects - multiple effects at the same time.
Combining these leads to any number of animation sequences, and many of the useful sequence are prepackaged.
The visual effects demo provides many spotlight effects.
FAT is a library allowing easy scripting of a transition from one colour to another.
The Time Periodic Refresh demo shows the server time, updated every few seconds. It's not clear exactly when the time has changed, however, so this refactoring adds a spotlight effect each time a new result arrives from the server. There are actually a couple of refactorings here: one is hand-built, and the other illustrates reuse of the scriptaculous library.
The Time Spotlight Demo lets the user set a few parameters and applies the corresponding effect ( Figure 1.82, “Flexible Fader Demo”). A fader object encapsulates the fading logic. The fade duration and transition interval are modifiable attributes:
fader.durationTime = parseInt($("fadeDuration").value);
fader.transitionInterval = parseInt($("transitionInterval").value);
The application asks fader to fade the div as soon as it's been modified:
function showCustomTime(text) {
var customTimeLabel = $("customTimeLabel");
customTimeLabel.innerHTML = text + "." + callingContext;
fader.fade(customTimeLabel, $("startColor").value, $("endColor").value);
}
fader then kicks off the first transition, passing in a timeSoFar parameter of zero. The function is simpler using an array of percentage color values, but hex is more common, so a simple conversion takes place:
fade: function(element, startRGB, endRGB) {
this.nextTransition(
element, this.rgbToPercents(startRGB), this.rgbToPercents(endRGB),0);
}
Each transition involves deciding how far along the fade it is, and calculating the corresponding color style using a linear interpolation (as explained in the Solution above):
nextTransition: function(element, startColor, endColor, timeSoFar) {
...
var currentColor = "rgb(";
for (component=0; component<3; component++) {
var currentComponent = Math.round(startColor[component] +
proportionSoFar * (endColor[component] - startColor[component]));
currentColor+=currentComponent + "%" + (component<2 ? "," : ")");
}
element.style.backgroundColor = currentColor;
...
}
Then it increments timeSoFar and finishes the fade if fade time has expired:
timeSoFar+=this.transitionInterval;
if (timeSoFar>=this.durationTime) {
this.durationTime+ "\n";
element.style.backgroundColor =
"rgb("+endColor[0]+"%,"+endColor[1]+"%,"+endColor[2]+"%)";
return;
}
var nextCall = function() {
fader.nextTransition(element, startColor, endColor, timeSoFar);
}
setTimeout(nextCall, this.transitionInterval);
fader is coded for simplicity, and a couple of improvements would be possible. First, the repeated color calculation would be more effective if it worked on the per-transition delta instead of calculating the absolute color each time. Also, the timing could be adjusted to take into account the time taken to run the function itself.
The Time Scriptactulous Demo shows how easy it is to reuse an existing effects library. Here, the time displays show a Materialise effect when a new result appears. They transition from completely invisible (showing only the document background colour) to the appearance determined by their class's style.
The refactoring is trivial. Include the scriptaculous effects library, effects.js, and prototype.js, a general-purpose Javascript utility used by scriptaculous:
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="effects.js"></script>
Then, as with the hand-built fader above, invoking the effect is a one-liner:
new Effect.Appear("defaultTimeLabel");
“One-Second Mutation” and “One-Second Motion” are also used to draw attention to a significant event. One-Second Spotlight can be used as both a general attention device as well as to hint at a specific type of event, whereas those two patterns tend to be slightly more about depicting specific events. The effects can also be combnined, e.g. shrink an object as it fades away.
A change arising from a “Periodic Refresh” is often marked with a “One-Second Spotlight”.
The pattern's name is the key here: a spotlight can be used to direct the audience's attention.
37Signals introduced the Yellow Fade Technique to its products and their Yellow Fade Technique article helped spread the meme.