AJAX - Yellow Fade Technique

My first technical post: AJAX - Yellow Fade Technique...

Dear Friends,

We might have seen in many pages about the Yellow Fade Technique. It’s mainly used in AJAX. Well, I will explain it now.

Explanation

“There is something happening here, but you don’t know what it is. Do you Mr. Jones?” - Bob Dylan

A lot of web sites & applications make you feel a bit like Mr. Jones.

[​IMG]

That’s why we’ve pioneered the Yellow Fade Technique (YFT). It’s a nifty way to subtly spotlight a recently changed area on a page.

Why does this matter? When you edit or move something on a web page it usually forces a reload of that page. The problem is once the page reloads it’s often difficult to spot and confirm the change (especially if the change occurred somewhere in the middle of the page). The YFT uses JavaScript to create a yellow highlight that briefly spotlights the change when the page reloads. Then, in a second or two, the highlight fades and the page reverts to its normal state. The YFT makes it super easy to spot edits/changes yet its unobtrusive nature lets people quickly get back to work once a modification is confirmed.

Let’s take a look at an example.

Let’s say I want to change the name of the second post on this Basecamp page from “CEO Photo” to “Jim Messier Photo.”

[​IMG]

First off, I’ll go to the “Edit Post” page and change the post’s title.

[​IMG]

Once I save the change, the original page then reloads with the YFT (the yellow highlights the post I just changed). In the subsequent images, you can see how the yellow slowly fades out so it doesn’t dominate the layout forever.


[​IMG]

[​IMG]

[​IMG]

Voila, the page is back to normal within seconds.

Implementation

To see it in action, here’s an example, how to do it. This is the most simplest implementation I can ever give you.

<script type="text/javascript">
function yellowFade(el)
{
  var b = 100;
  function f()
  {
    el.style.background = 'rgb(255,255,'+ (b+=4) +')';
    if (b < 255)
    {
      setTimeout(f, 20);
    }
  };
  f();
}
</script>

This is the script of the core function to be used. Rather than using some libraries like Scriptaculous, we can use this small snippet. Now you can trigger the fade with the help of any button or element.

I have done a coding with a small div tag and a button. Also there’s another div tag with an onmouseover event.

Complete Code:

<html>
<head>
<title>Yellow Fade Technique</title>
<script language="JavaScript">
function yellowFade(el)
{
  var b = 100;
  function f()
  {
    el.style.background = 'rgb(255,255,'+ (b+=4) +')';
    if (b < 255)
    {
      setTimeout(f, 20);
    }
  };
  f();
}
</script>
</head>

<body>
  <div style="width:100px; height:100px" id="theDiv"></div><br>
  <input type="button" value="Do Fading!"
     onClick="yellowFade(document.getElementById('theDiv'));"><br>
  &nbsp;
  <div style="width:100px; height:100px; text-align:center;
    padding-top: 40px; font-family: calibri, tahoma; font-size: small"
    onmouseover="yellowFade(this);">MouseOver</div>
</body>
</html>

For execution, copy this Complete Code and paste it in notepad and save it as any HTML document (eg. fade.htm) and open it with any browser (Internet Explorer or Mozilla Firefox).

Comments are welcome!

The full article's source link: #-Link-Snipped-# Enjoy! 😁 😁

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Reya

    Reya

    @reya-SMihdC Mar 2, 2011

    Hey superb!Its working😀 😀😀

  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Mar 2, 2011

    praveena211Hey superb!Its working😀 😀😀

    Congrats!!! 😁