HTML DOM clip 屬性
定義和用法
clip 屬性設(shè)置元素的形狀。
當(dāng)圖像大于它所在的元素時會發(fā)生什么?"clip" 屬性允許你規(guī)定元素的可見尺寸,以及元素被裁剪和顯示的形狀。
語法:
Object.style.clip=rect(top,right,bottom,left)|auto
可能的值
值 | 描述 |
---|---|
rect(top,right,bottom,left) | 設(shè)置元素的形狀。 |
auto | 瀏覽器設(shè)置元素的形狀。 |
提示和注釋
注釋:該屬性不能用于 "overflow" 設(shè)置為 "visible" 的元素。
實例
本例把圖像裁剪為指定的形狀:
<html>
<head>
<style type="text/css">
img
{
position:absolute;
top:100px;
}
</style>
<script type="text/javascript">
function clipImage()
{
document.getElementById("img1").style.clip="rect(0px,50px,50px,0px)";
}
</script>
</head>
<body>
<img id="img1" border="0" src="logocss.gif" width="95" height="84" />
<input type="button" onclick=clipImage() value="Clip image" />
</body>
</html>