Style clip 屬性

Style 對象參考手冊 Style 對象

定義和用法

clip 屬性設置或返回定位元素的可見部分。

語法

設置 clip 屬性:

Object.style.clip="auto|rect(top right bottom left)|inherit"

返回 clip 屬性:

Object.style.clip

描述
auto 默認。元素沒有剪輯。
rect(top right bottom left) 剪輯的形狀由四個座標定義。
inherit clip 屬性的值從父元素繼承。


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 clip 屬性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


實例

實例

剪輯圖像為指定的形狀:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<style type="text/css">
img{
position:absolute;
    top:100px;
}
</style>
<script>
function clipImage(){
    document.getElementById("img1").style.clip="rect(0px 75px 75px 0px)";
}
function clearClip(){
    document.getElementById("img1").style.clip="auto";
}
</script>
</head>
<body>

<img id="img1" src="w3javascript.gif" width="100" height="132">
<input type="button" onclick=clipImage() value="裁剪圖片">
<input type="button" onclick=clearClip() value="不裁剪圖片">

</body>
</html>



Style 對象參考手冊 Style 對象