Latest web development tutorials

HTML DOM 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>本教程(w3big.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對象