日期:2014-05-16 浏览次数:20374 次
Book_Image_Sources=new Array( "[color=#FF0000]images/englishBook.gif[/color]","#", "[color=#FF0000]images/englishBook.gif[/color]","#", "[color=#FF0000]images/englishBook.gif[/color]","#", );
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> div { margin:20px; width:280px; height:381px; background: url('http://img.my.csdn.net/uploads/201205/08/1336442293_9753.gif'); } .a { background-position:center; } .b { background-position:bottom; } </style> </head> <body> <div></div> <div class="a"></div> <div class="b"></div> <script> </script> </body> </html>
------解决方案--------------------
直接用ps分成3张图不行?
------解决方案--------------------
干嘛不人工分割后再显示?
楼主的意思是用js动态分割图片生成新图片再进行展示吗?
如果是那样,canvas好像是有这样的图片处理能力的
------解决方案--------------------
设置cssText属性,可以用js先计算,再设置数组中的值
<!doctype html > <html><head> <title> new document </title> <script type="text/javascript"> Book_Image_Sources = new Array( "width:280px; height:381px; background:url(http://img.my.csdn.net/uploads/201205/08/1336442293_9753.gif)","#", "width:280px; height:381px; background:url(http://img.my.csdn.net/uploads/201205/08/1336442293_9753.gif) 0 -381px;","#", "width:280px; height:381px; background:url(http://img.my.csdn.net/uploads/201205/08/1336442293_9753.gif) 0 -762px;","#" ); window.onload = function(){ var d = document.getElementsByTagName("div"); for(var i = 0; i < d.length; i++){ d[i].style.cssText = Book_Image_Sources[i*2]; } }; </script> </head> <body> <div></div> <br> <div></div> <br> <div></div> </body> </html>
------解决方案--------------------
css的clip,可以通过 js来操作,参考下
<!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></title>
<head>
<style type="text/css">
img
{
position:absolute;
clip:rect(10px 80px 151px 0px);
}
</style>
</head>
<body>
<p>clip 属性剪切了一幅图像:</p>
<p><img border="0" src="http://www.w3school.com.cn/i/eg_bookasp.gif"></p>