Prototype - setOpacity() 方法



此方法設定元素的可視不透明度,同時解決在不同的瀏覽器中的差異。

不透明度引數應該是一個浮點數,其中值 0 為完全透明,1 為完全不透明。

Element.setStyle 方法內部使用 setOpacity 來設定不透明度。

語法

element.setOpacity(opacity);

返回值

返回一個 HTML 元素。

示例

<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>

輸出

prototype_element_object.htm
廣告
© . All rights reserved.