當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


script.aculo.us Grow效果用法及代碼示例

script.aculo.us庫是一個跨瀏覽器庫,旨在改善網站的用戶界麵。在本文中,我們將演示增長效應。此效果用於使元素從一個方向平滑過渡地生長。我們也可以調整效果的持續時間。

用法:

Effect.Grow( 'id_of_element', [options] )

或者

Effect.Grow( element, [options] )

選項:此選項對象具有上麵提到的和下麵描述的兩個值:

  • direction:此值指定元素增長的起點。值可以是“左上”,“右上”,“左下”或“右下”。默認值為‘center’。
  • duration:此值以秒為單位指定效果的持續時間。默認值為1秒。

為了演示此函數的使用,我們編寫了一小段代碼。在其中,我們編寫了一個名為ShowEffect方法的小型JavaScript函數,該函數使用此庫的Grow方法。下麵的示例演示了該方法。



範例1:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script type="text/javascript" 
        src="prototype.js"> 
    </script> 
  
    <script type="text/javascript" 
        src="scriptaculous.js"> 
    </script> 
  
    <script type="text/javascript"> 
        function ShowEffect(element) { 
  
            // Using the Effect.Grow() method 
            // on the element with no options 
            new Effect.Grow(element); 
        } 
    </script> 
</head> 
  
<body> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <h2>script.aculo.us Grow Effect</h2> 
      
    <button onclick="ShowEffect('geeks_1')"> 
        Click to Show the Effect 
    </button> 
    <br /> 
    <br /> 
  
    <div id="geeks_1"> 
        <div style="background-color:lightgreen;"> 
            GeeksforGeeks 
        </div> 
    </div> 
</body> 
  
</html>

輸出:

範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script type="text/javascript" 
        src="prototype.js"> 
    </script> 
  
    <script type="text/javascript" 
        src="scriptaculous.js"> 
    </script> 
  
    <script type="text/javascript"> 
        function ShowEffect(element) { 
  
            // Using the Effect.Grow() method 
            // on the element with the direction 
            // and duration sepcified 
            new Effect.Grow(element, { 
                direction:'top-left', 
                duration:5 
            }); 
        } 
    </script> 
</head> 
  
<body> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <h2>script.aculo.us Grow Effect</h2> 
      
    <button onclick="ShowEffect('hideshow')"> 
        Click to Show the Effect 
    </button> 
    <br /> 
    <br /> 
    <div id="hideshow"> 
        LINE TO GROW 
    </div> 
</body> 
  
</html>

輸出:

相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 script.aculo.us Grow Effect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。