在本文中,我們將通過使用一個名為script.aculo.us的JavaScript庫來演示Squish效果,該庫可以平滑縮小尺寸,而左角保持靜止。我們也可以調整效果的持續時間。
用法:
Effect.Squish('id_of_element'); // Or Effect.Squish('id_of_element', { duration:dur });
參數:
- id_of_element:它包含要在其上應用效果的元素。
- duration:它保留了此效果所花費的持續時間。
注意:要使用此庫,我們應該下載或安裝該庫,然後在我們的程序中使用它。為此,您可以點擊此鏈接http://script.aculo.us/downloads。
方法:
- 為了演示此函數的使用,我們編寫了一小段代碼。在其中,我們編寫了一個名為SquishEffect()方法的小型JavaScript函數,該函數使用此庫的Squish()方法。
- 通過單擊“單擊要擠壓的圖像”,您將清楚地看到效果。
範例1:要查看效果,請先安裝該庫,然後在本地環境中打開以下程序。
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src="prototype.js">
</script>
<script type="text/javascript"
src="scriptaculous.js?load = effects">
</script>
<script type="text/javascript">
function GFGSquish(el) {
new Effect.Squish(el, { duration:4 });
}
</script>
</head>
<body>
<div id="myimage" onclick="GFGSquish(this);">
<img height=200px width=200px
src="gfg.png" alt="gfg logo" />
<h2>Click here to see the Squish effect </h2>
</div>
</body>
</html>
輸出:
範例2:在此示例中,我們更改了效果的持續時間,還添加了一個按鈕來查看效果。
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src="prototype.js">
</script>
<script type="text/javascript"
src="scriptaculous.js?load = effects">
</script>
<script type="text/javascript">
function GFGSquish(el) {
new Effect.Squish(el, { duration:3 });
}
</script>
</head>
<body>
<div id="myimage">
<img height=200px width=200px
src="gfg.png" alt="gfg logo" />
<br><br>
<button onclick="GFGSquish('myimage');">
Click here to see the effect
</button>
</div>
</body>
</html>
輸出:
相關用法
注:本文由純淨天空篩選整理自parasmadan15大神的英文原創作品 script.aculo.us Squish Effect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。