Style clipProperty

Style 对象参考手册Style Object

Definition and Usage

The clip property sets or returns the visible portion of a positioned element.

Syntax

Set the clip property:

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

Return the clip property:

Object.style.clip

Value Description
auto Default. The element is not clipped.
rect(top right bottom left) The shape of the clipped area is defined by four coordinates.
inherit The value of the clip property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the clip property.

Note:IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Clip the image into a specified shape:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.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.html" width="100" height="132">
<input type="button" onclick=clipImage() value="Clip image">
<input type="button" onclick=clearClip() value="Do not clip image">

</body>
</html>

Try it Yourself »


Style 对象参考手册Style Object Other Extensions