Prototype - setOpacity() Method



This method sets the visual opacity of an element while working around inconsistencies in various browsers.

The opacity argument should be a floating point number, where the value of 0 is fully transparent and 1 is fully opaque.

Element.setStyle method uses setOpacity internally to set opacity.

Syntax

element.setOpacity(opacity);

Return Value

Returns an HTML element.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function reduceOpacity() {
            $('test').setOpacity( 0.5 );
            // This is equivalent to 
            // Element.setStyle({ opacity: 0.5 });
         }
      </script>
   </head>

   <body">
      <p id = "test">Click the button to see the result.</p>
      <input type = "button" value = "Click" onclick = "reduceOpacity();"/>
   </body>
</html>

Output

prototype_element_object.htm
Advertisements