Open In App

script.aculo.us Visual Effects

The Visual effects module comes with six-core effects: Opacity, Scale, Morph, MoveBy, Highlight, and Parallel. Through the combination of these core effects there are over 16 additional effects eg: effect, Appear, effect, Toggle, etc.

Core Effects:



Additional Effects:

All the core effects support various common parameters, also some effects have effect-specific parameters. These effect names are case-sensitive



Common Parameters:

Options

Description

duration

To specify the duration of the effect (in float)

fps

To specify the number of frames to be targeted in one second

transition

Gives a function that modifies the current points of the animation(between 0 and 1). Available transitions: 

  • Effect.Transitions.sinoidal
  • Effect.Transitions.linear
  • Effect.Transitions.reverse
  • Effect.Transitions.wobble
  • Effect.Transitions.flicker
  • Effect.Transitions.pulse
  • Effect.Transitions.spring
  • Effect.Transitions.none
  • Effect.Transitions.full

from

Sets the starting point of the transition, takes float value between 0 and 1.

to

Sets the endpoint of the transition, takes float value between 0 and 1.

sync

If set to true, you can render frames manually by calling the render() instance method of an effect. 

By default, frames render automatically

queue

Can be used to set queuing options 

delay 

Can be used to set delay in an effect.

Example:




<html>
<head>
    <script type="text/javascript" 
            src="./javascript/prototype.js">
    </script>
    <script type="text/javascript" 
            src=
"./javascript/scriptaculous.js?load = effects">
    </script>
    <script>
        function transitionEffect(element) {
            new Effect.Opacity(element, {
                duration: 2.0,
                transition: Effect.Transitions.linear,
                from: 1.0,
                to: 0.5
            });
        };
    </script>
</head>
  
<body>   
    <div onclick=transitionEffect(div)>
        <button>Transition</button>
    </div>
    <div id="div">   
        <p>Transition of the text 
           (changing opacity)</p>
    </div>
</body>
  
</html>

Output:

Callback Methods: The options parameter can also be supplied with callback methods so that you can have the script executed at various events while the effect is running. The callbacks are supplied with a reference to the effect object as a parameter.

callback

Description

beforeStart

It is called before the effects rendering loop is started.

beforeSetup

It is called before the effect is set up.

afterSetup

It is called after the effect is set up and immediately before the main effects rendering loop is started.

beforeUpdate

It is called on each iteration of the effects rendering loop before redraw takes place.

afterUpdate

It is called on each iteration of the effects rendering loop after redraw takes place.

afterFinish

It is called after the last redraw of the effect was made.

Example:




<html>
<head>
    <script type = "text/javascript" 
            src = "./javascript/prototype.js">
    </script>
    <script type = "text/javascript" 
            src
"./javascript/scriptaculous.js?load = effects">
    </script>
    <script>
        function OnFinish(div){
            alert("OnFinish called: " + div.element.id);
        }
       
        function OnStart(div){
            alert("OnStart called: " + div.element.id);
        }
       
        function callBackMethods(div){
            new Effect.Highlight(div, 
            {
                duration: 0.5,
                afterFinish: OnFinish,
                beforeStart: OnStart
            }
            );
        }
    </script>
</head>
  
<body>
    <div onclick = "callBackMethods(this)" id = "div">
        <button>callBack</button>
    </div>      
</body>
  
</html>

Output:

Properties of and methods:

Variable

Description

effect.element

The element on which the effect is applied.

effect.options

It holds the options given to the effect.

effect.currentFrame

It is the number of the frame rendered lastly.

effect.startOn,

effect.finishOn

It is the time (in ms) when the effect was started, and when it will be finished.

effect.effects[]

On an Effect.Parallel effect, there’s an effects[] array containing the individual effects the parallel effect is composed of.

effect.cancel()

It is used to stop the effect as is.

effect.inspect()

It is used to get the basic debugging information about the instance.

Article Tags :