In this article you learn how to create a fading text banner, a fading text banner with several different messages that fade in and out, and a fading image banner with several different image banners that fade in and out. You also learn how to use the document.write method so that you can give a link to others to include your banners in their webpage.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site
Your Ad Here!
Your ad here for one full year, only $20. Send me your ad copy, up to six lines, I'll post it ASAP. After you inspect your ad online, you can pay through PayPal.
Click here for more information.

Easy Fading Text Banner Code

If your banner is static, it can easily be overlooked by your web site's visitors. Any type of animation can draw a visitor's eye to your message. One type of animation is the fade. With only a few lines of java script code you can create a fading text banner.

In this article, I'll provide you with easy code for a fading text banner. Then I'll provide you with easy code for a fading text banner where several different messages fade in and out. And, as a bonus, I'll also provide you with code to do the same fading effect with an image banner.

First, let's do a basic example. Shown below is the html code for a div element which contains a paragraph element that displays the text "This is My Banner Text". Paste this code into the body section of your webpage.

<div id="banfade" style="display:inline; width:468px; height:60px; border-style:solid; border-color:black; border-width:2px; color:#000000">
<p align="center" style="font-family:verdana; font-size:26px; font-weight:bold; margin-top:10px;">This is My Banner Text</p>
</div>

Note that I applied a bunch of inline style rules to both elements. If you're familiar with the use of cascading style sheets, then you know that you can place these rules in an embedded style block or in a linked style sheet. If you're not familiar with the use of cascading style rules, just keep the inline style rules.

Unfortunately, I don't have space in this article to explain cascading style sheets in detail, but, among other things, the style rules define a standard 468 x 60 pixel banner that flows with the other text and html elements on your webpage.

Now we need a java script function to make the text fade. Paste the java script code block shown below into the head section of your webpage.

<script type="text/javascript">
var arColor = ["#000000","#404040","#808080","#c0c0c0","#ffffff"];
var i = 0;

function fadeText()
{
  if(i == arColor.length - 1) i = 0;
  else i++;
  document.getElementById("banfade").style.color = arColor[i];
}

setInterval("fadeText()", 1000);
</script>

The first line in the code defines an array which contains five elements. Each array element is a different color specified in hexadecimal format. Unfortunately, I don't have space in this article to explain hexadecimal color format in detail, but the first element in the array contains hexadecimal code for the color black, the last element in the array contains hexadecimal code for the color white.

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Timer Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Web Designer's Reference
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269