Tuesday, June 16, 2026
HomeLanguagesJavascriptscript.aculo.us Fade Effect

script.aculo.us Fade Effect

In this article, we will demonstrate the effect of Fade by using a JavaScript library called script.aculo.us. The fade effect offers a smooth fading transition to the element. We can also adjust the duration of this effect as well.

Syntax:

Effect.Fade('element_id');

// or

Effect.Fade('element_id', options );

Options:

  • duration: Duration taken to fade the element, defaults to 1.0.
  • from: It is a float value representing the percent of opacity to start, the default value is 0.0.
  • to: It is a float value representing the percent of opacity to end, the default value is 1.0.

Note: To use this library, we are supposed to install the library and then use it in our programs. And to do so, you can follow this link http://script.aculo.us/downloads.

Example 1: To demonstrate the use of this function, we have written a small piece of code. In which we have written a small JavaScript function named ShowEffect method which uses the Fade method of this library. By clicking on Click me to Fade the line! , you will see the effect clearly.

To see the effect, first install the library and then open this program in the local environment.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
        src="prototype.js">
    </script>
      
    <script type="text/javascript" 
        src="scriptaculous.js?load = effects,controls">
    </script>
      
    <script type="text/javascript">
        function ShowAction(element) {
            new Effect.Fade(element, 
            { duration: 1, from: 0, to: 1.0 });
        }
    </script>
</head>
  
<body>
    <div onclick="ShowAction('hideshow')">
        <button type="button">
            Click me to Fade the line!
        </button>
    </div>
    <br><br>
  
    <div id="hideshow">
        LINE TO FADE
    </div>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
        src="prototype.js">
    </script>
      
    <script type="text/javascript" 
    src="scriptaculous.js?load = effects,controls">
    </script>
      
    <script type="text/javascript">
        function ShowEffect(element) {
            new Effect.Fade(element, 
            { duration: 2, from: 0, to: 1.0 });
        }
    </script>
</head>
  
<body>
    <div onclick="ShowEffect('neveropen_1')">
        <button type="button">
            Click me to ShowEffect!
        </button>
    </div>
    <br><br>
  
    <div id="neveropen_1">
        <div style="width: 10%; height: 10%; 
            background-color: green;">
            Geeks For Geeks
        </div>
    </div>
</body>
  
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS