You've probably seen websites where a picture fades out, being replaced by another picture that fades in. Or maybe you've seen a picture that replaces another picture by appearing as an expanding circle inside the first picture. In this article give you some easy code to do just that!
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

Win a new iPod with video!

Easy Picture Transition Effects

You've probably seen websites where a picture fades out, being replaced by another picture that fades in. Or maybe you've seen a picture that replaces another picture by appearing as an expanding circle inside the first picture. Wouldn't it be nice if you could use these cool effects on your own web page? In this article, I'm going to give you some easy code to do just that!

This type of effect is called a "Visual Transition". They are usually accomplished by using complicated dhtml code involving layers and clipping, but in Internet Explorer version 5.5 and higher, some of these effects have been built-in to the browser. This means that you can make them work using a small amount of easy JavaScript code.

The bad news is that this code is not W3C standard and will NOT work in browsers like Netscape Navigator, or Mozilla, or with versions of Internet Explorer before 5.5. The good news is that almost everybody is using Internet Explorer 5.5 and higher.

The first thing you'll need for this example is two images to transition between. Crop or resize the images so that they have the same width and height. In this example, I use images named flower1.jpg and flower2.jpg, both 300 x 300 pixels in dimensions.


Click on the button to start the transition effect. To use this example, right-click on each picture and select Save Picture As... in the popup menu that appears. (Reload the page to get the first picture). Then copy and paste the following code into the body of your webpage.

<img id="image1" width=300 height=300 src="flower1.jpg" style="filter:blendTrans(duration=3);"> <br><input type=button value="Start" onClick="doTransition()">
<img src="flower2.jpg" style="position:relative; width:1; height:1; visibility:hidden">

The first line in the code displays the initial picture, setting the "blendTrans" filter with a duration of three seconds. The second line provides a button to start the transition. The third line preloads the second picture, setting its style so that it is not visisble and does not take up any space on the screen (except 1 pixel).

Note that the onClick event of the button calls a function named doTransition. The entire JavaScript code for the doTransition function is shown below. Cut and paste this block of code into the head section of your webpage.

<script language=JavaScript>
function doTransition()
{
image1.filters.blendTrans.Apply();
image1.src="flower2.jpg";
image1.filters.blendTrans.Play();
}
</script>

If you don't like the button, change the code in the body of your webpage to that shown below. Now the user can click on the image itself to start the transition. Or you could call the doTransition from the onLoad event of your webpage's body tag to have the transition start automatically when the webpage loads.

<img id="image1" src="flower1.jpg" style="filter:blendTrans(duration=3)" onclick="doTrans()"><br>
Click image to start Transition.
<img src="flower2.jpg" style="position:relative; width:1; height:1; visibility:hidden">

Web Design Sections

RSS Feed RSS Feed

Easy Java Script 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
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

Get paid cash typically $4 to $25 for each survey you complete!

[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