利用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坐标(水平方向)的终点
注:坐标的起点是在左上角
<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坐标(水平方向)的终点
注:坐标的起点是在左上角
相关文章推荐
- HTML+CSS实现合并图片的切割显示以及背景渲染
- 如何利用CSS代码使图片和文字在同一行显示且对齐
- 用DIV+CSS切割多背景合并图片 CSS Sprites 技术
- 用DIV+CSS切割多背景合并图片 CSS Sprites 技术
- 利用CSS设置背景图片不显示的问题
- Android中利用OnTouchListener在中ImageView中动态显示图片
- js利用object标签显示动态图片
- 用DIV+CSS切割多背景合并图片 CSS Sprites 技术
- 关于web前端,css小技巧的笔记——图片动态比例显示
- 利用css将文字和图片水平垂直居中显示
- 利用C#,SqlXml技术将NorthWind中的所有记录取出并显示出来(包括员工图片)
- 关于在struts2中利用jquery中如何动态从数据库中加载图片并显示
- 如何利用CSS代码使图片和文字在同一行显示且对齐
- 利用DataURL技术在网页上显示图片
- 解决水晶报表中动态加载的图片或利用水晶报表创建的图表不显示图片的方法
- 谈一谈分别利用opencv、Qt、matlab动态显示图片的实现
- 利用IPicture接口加载、显示图片
- Servlet 动态显示图片
- 利用Wipe等ActiveX技术,实现n(n>>2)幅图片轮换擦洗显示
- 如何在水晶报表中动态显示任意格式的图片?