Prototype-element-setopacity

提供:Dev Guides
移動先:案内検索

プロトタイプ-setOpacity()メソッド

このメソッドは、さまざまなブラウザーの不整合を回避しながら、要素の視覚的不透明度を設定します。

opacity引数は浮動小数点数である必要があります。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>

出力