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


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

script.aculo.us庫是一個跨瀏覽器庫,旨在改善網站的用戶界麵。在本文中,我們將演示“變形”效果。此效果用於將元素的CSS樣式平滑地更改為作為參數給出的樣式。我們也可以調整效果的持續時間。

用法:

Effect.Morph( 'element', [options] )

參數:該效果在下麵描述的options對象中具有單個參數:

  • style:這代表效果平滑變化的CSS樣式。

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

範例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 Morph effect by specifying 
            // new CSS styles 
            new Effect.Morph(element, { 
                style:'background:#f00; color:#fff;' 
            }); 
        } 
    </script> 
</head> 
  
<body> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <h2>script.aculo.us Morph Effect</h2> 
      
    <button onclick="ShowEffect('hideshow')"> 
        Click me to Morph the line! 
    </button> 
    <br /> 
    <br /> 
  
    <div id="hideshow" style="background:#cccccc;"> 
        LINE TO MORPH 
    </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 Morph effect by  
            // specifying new CSS styles 
            new Effect.Morph(element, { 
                style:  
'height:100px; width:150px; color:#FF0000;' 
            }); 
        } 
    </script> 
</head> 
  
<body> 
    <h1 style="color:green;"> 
        GeeksforGeeks 
    </h1> 
  
    <h2>script.aculo.us Morph Effect</h2> 
      
    <button onclick="ShowEffect('hideshow')"> 
        Click me to Morph the element! 
    </button> 
    <br /> 
    <br /> 
  
    <div id="hideshow" style= 
        "background:lightgreen;"> 
        Element to Morph 
    </div> 
</body> 
  
</html>

輸出:

相關用法


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