Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype setOpacity() Method


previous next AddThis Social Bookmark Button


Advertisements

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>

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements