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 屬性的值從父元素繼承。 |
浏覽器支援

所有主要浏覽器都支援 clip 屬性。
注意:IE7 及更早的版本不支援 "inherit" 值。IE8 隻有規定了 !DOCTYPE 才支援 "inherit"。IE9 支援 "inherit"。
執行個體
剪輯圖像為指定的形狀:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.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 loading="lazy" id="img1" src="w3javascript.gif" width="100" height="132">
<input type="button" onclick=clipImage() value="裁剪圖檔">
<input type="button" onclick=clearClip() value="不裁剪圖檔">
</body>
</html>
Style 對象