您的位置:首页 > Web前端 > CSS

利用CSS切割图片技术来动态显示图片

2014-07-06 16:26 363 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>利用CSS切割图片来切换图片</title>
<style type="text/css">
.img2
{
position:absolute;
clip:rect(0px 20px 20px 0px);
}
.img1
{
position:absolute;
clip:rect(0px 60px 60px 20px);
left:-11px
}
</style>
<script type="text/javascript">
function switchimgcss(obj)
{
//document.getElementById("img_css").className
//document.getElementById("img_css").className="img1"
if (obj.className=="img1")
{
obj.className=""; //该语句不能省略
obj.className="img2";

}
else{
obj.className="";
obj.className="img1";
}
}
</script>
</head>
<body>
<p>clip 属性用于剪切图片:</p>
<p><img src="../images/time.gif" id="img_css" width="100" height="29" class="img2" /></p>
</body>
</html>

css通过控制显示图片的位置来实现图片的剪切
clip:rect(y1 y1 x2 x1)吧
y1=定位的y坐标(垂直方向)的起点
x1=定位的x坐标(水平方向)的起点
y2=定位的y坐标(垂直方向)的终点
x2=定位的x坐标(水平方向)的终点
注:坐标的起点是在左上角
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  css html