Style clipプロパティ
Style オブジェクト
定義と使い方
clip プロパティは、配置された要素の表示可能な部分を設定または返します。
構文
clip プロパティを設定する:
Object.style.clip="auto|rect(top right bottom left)|inherit"
clip プロパティを返す:
Object.style.clip
| 值 | 説明 |
|---|---|
| auto | デフォルト。要素はクリップされません。 |
| rect(top right bottom left) | クリップの形状は4つの座標で定義されます。 |
| inherit | clip プロパティの値は親要素から継承されます。 |
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが clip プロパティをサポートしています。
注意:IE7 およびそれ以前のバージョンは "inherit" 値をサポートしていません。IE8 は !DOCTYPE が指定されている場合にのみ "inherit" をサポートします。IE9 は "inherit" をサポートします。
例
例
画像を指定した形状にクリップします:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(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="画像を切り取る">
<input type="button" onclick=clearClip() value="画像を切り取らない">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(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="画像を切り取る">
<input type="button" onclick=clearClip() value="画像を切り取らない">
</body>
</html>
試してみる »
Style オブジェクト その他の拡張