JavaScript: Slowly Fade Using Opacity

The JavaScript Fade Anything Technique is great for fading a specified background color of an element back to its native color, but I wanted to dissolve an entire div, including one with images, which the current version of the Fade Anything method doesn’t allow for. After an unsuccessful search for something to suit my needs, I built my own.

Include the reference to the JavaScript file in the header of your HTML. Surround whatever you want to fade with a div tag. Apply an onclick or onmouseover method to run "javascript:slowly.fade('whatever');", making sure to assign an id to the div tag to match (i.e. id="whatever").

var opacity = 96; // Avoid starting at 100% due to Mozilla bug
var slowly = {
  fade : function (id) {
    this.fadeLoop(id, opacity);
  },
  fadeLoop : function (id, opacity) {
    var o = document.getElementById(id);
    if (opacity >= 5) {
      slowly.setOpacity(o, opacity);
      opacity -= 4;
      window.setTimeout("slowly.fadeLoop('"+id+"', "+opacity+")", 50);
    } else {
      o.style.display = "none";
    }
  },
  setOpacity : function (o, opacity) {
    o.style.filter = "alpha(style=0,opacity:" + opacity + ")";  // IE
    o.style.KHTMLOpacity = opacity / 100;           // Konqueror
    o.style.MozOpacity = opacity / 100;	            // Mozilla (old)
    o.style.opacity = opacity / 100;                // Mozilla (new)
  }
}

Works in IE6+, Firefox 1.5+, Chrome.

Save your own copy of the SlowlyFade file — do not steal my bandwidth, please!

As always, this script is provided as-is, without any warranty of any kind, express, implied or otherwise, including without limitation, any warranty of merchantability or fitness for a particular purpose. In no event shall I be liable for any special, incidental, consequential or indirect damages of any kind, or any damages whatsoever resulting from loss of; use, data or profits, whether or not advised of the possibility of damage, and on any theory of liability, arising out of or in connection with the use or performance of this script.

Click anywhere in this box to get rid of this annoying status message. This is a working demonstration of how the SlowlyFade function works.



Want Steak? Speak English!

Six months ago, Joey Vento (the owner of Geno’s Steaks in Philadelphia) put up a sign in his restaurant that reads, “This is America — when ordering speak English.” He states that he added the sign to encourage immigrants to learn the language.

Of course, a bunch of whiny, immigrant activists have labeled his actions as racist. Roberto Santiago, executive director of Philadelphia’s Council of Spanish Speaking Organizations (the organization’s name conspicuously missing a hyphen, most likely due to someone’s poor knowledge of English punctuation), says that Joey is expressing the message that “I don’t like these brown faces in my community and I will do everything I can to get them out of there.”

What a load of crap! The sign doesn’t say anything about brown faces, Latinos, or even Spanish-speaking people. People like Roberto Santiago — who encourage immigrants, legal and otherwise, to snub US society and expect everything to be bilingual to serve their own selfish needs — are actually suppressing immigrants by encouraging them to be unfit for US jobs and more fit for welfare. Joey did not make the issue racist. It is Roberto and other like-minded, self-centered, myopic individuals who are playing the race card for their own personal gain.

I don’t care what color someone’s skin is or where they came from; in my position I work with a lot of immigrants. In fact no one on my development team is actually from the United States; instead they are from India, Australia, Iraq, Ukraine, and China. They are all educated, English-speaking, legal immigrants. I support them, and admire their integrity and determination. On the other hand, my less educated, Spanish-speaking, most likely illegal immigrant gardeners — who probably make about eight bucks an hour after their dual-language-speaking boss pays them under the table — do not deserve any sympathy or respect for refusing to learn English or for crossing the border illegally.

I understand that Joey is not necessarily making a stand about illegal immigrants, only that immigrants should merge into US society by learning the language. He’s right. And I have yet to find a legal immigrant who disagrees. If a Korean immigrant comes here and expects to speak only Korean, works only with Koreans, and celebrates only Korean culture that person is not contributing to US society and should just go back home. The same applies to Mexicans, Germans, Italians, Swedes, Japanese, and everyone else. Blend in! Contribute to US society! Communicate with others around you! Speak English!

But I have a stand on illegal immigrants, as well as a stand on non-English-speaking immigrants. They (the ubiquitous “they”) say that illegal immigrants do the jobs we Americans refuse to do. That’s what high school and college students are for; they will gladly mow the lawn, wash cars, and work in fast food restaurants. Prison workers can work the farm fields. California is supposedly one of the country’s largest producer of fruits and vegetables. If these illegal workers are so plentiful and cheap and “good for California”, why is it that most of the fruits and vegetables in my local supermarket come from south of the border? Mexico, Chile, Argentina, Brazil…

It is because of lazy, uneducated, illegal immigrants that I and other English-speaking individuals must endure product packaging in both English and Spanish. It is because of lazy, uneducated, illegal immigrants that buses drive around town advertising some unknown thing in Spanish that 75% of the people living here can’t read anyway. It is because of lazy, uneducated, illegal immigrants that the crime rate is higher than it should be because they can’t make a standard living. It is because of lazy, uneducated, illegal immigrants that insurance and health care are so expensive.

I sent Joey an email:

Yay! I support you in your lonesome effort to encourage immigrants to learn the language and assimilate into US society. As a child, I lived in Germany. Could I expect everyone to provide everything in English to me? No, I had to learn German. I find it quite appalling that many immigrants to the US expect the opposite. Thank you very much for making a stand!

This is America — speak English.


A Typical WoW Conversation

[Party] [Mage] We’ve been looking for a 5th for UD strat for 2 hrs.
[Party] [Paladin] Looks like it’s not gonna happen…
[4. Looking For Group] [Hunter] 60 Hunter LFG UD Strat!
[Party] [Warrior] What about that rogue? What was his name – Xingxiao?
[Party] [Mage] He’s a farmer who /needs everything. Plus he doesn’t know how to sap
[Party] [Paladin] I can live without sap
[Party] [Priest] Nah he’s doing UBRS
[4. Looking For Group] [Hunter] 60 Hunter LFG UD Strat!!
[Party] [Warrior] Dammit! I can’t believe nobody wants to do strat
[Party] [Priest] What about a 54 lock? Too low?
[Party] [Paladin] Seriously guys, if we don’t find somebody soon I’m gonna go BG
[4. Looking For Group] [Hunter] 60 Hunter LFG UD Strat!!!!!
[Party] [Warrior] Gah! I was trying to invite the warlock and I accidentally invited that hunter
[Party] [Mage] WTF????
[Party] [Warrior] Was a MT… gøddåmn hunter’s been spamming me all night.
[Party] [Priest] OMFG – nice job, genius!!
Hunter has joined your party.
[Party] [Hunter] Sweet! Let’s do strat!
[Party] [Priest] Welcome!

If you’ve ever played World of Warcraft, you’ll understand.