图片切割工具---产生多个div切割图片 采用for和一的二维阵列设置背景位置
2015-09-18 09:30
423 查看
照片库
1.二维函数写法【效果展示】
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{margin:0;padding:0;}
body{background:#939393;}
#box{width:800px;height:800px;margin:0 auto;background:url(11.jpg);overflow: hidden;}
.col{width:50px;height:50px;outline:1px solid #fff;float:left;background:url(00.jpg) no-repeat;opacity:0;filter:alpha(opacity:0);}
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>
<script type="text/javascript">
var box=document.getElementById("box");
var rowDiv=[];
var tArray=new Array();
for(var i=0;i<16;i++) {
tArray[i] = new Array();
for (var j = 0; j < 16; j++) {
rowDiv[j] = document.createElement("div");
box.appendChild(rowDiv[j]);
rowDiv[j].className = "col";
tArray[i][j] = rowDiv[j];
var l = -(j * 50) + "px";
var T = -(i * 50) + "px";
tArray[i][j].style.backgroundPosition =l+" "+T;
tArray[i][j].onmouseover = function ()
{
this.style.opacity = "1";
this.style.filter="alpha(opacity:100)";
}
}
}
</script>
2.字符串写法【效果展示】
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{margin:0;padding:0;}
body{background:#939393;}
#box{width:800px;height:800px;margin:0 auto;background:url(11.jpg);overflow: hidden;}
.col{width:50px;height:50px;outline:1px solid #fff;float:left;background:url(00.jpg) no-repeat;opacity:0;filter:alpha(opacity:0);}
</style>
</head>
<script type="text/javascript" src="jquery-1.10.1.min.js"></script>
<body>
<div id="box"></div>
</body>
</html>
<script type="text/javascript">
var box=document.getElementById("box");
var col=box.getElementsByTagName("div");
var rowDiv=[];
var bg_P=[];
var str="";
for(var i=0;i<16;i++)
{
for(var j=0;j<16;j++)
{
str+='<div class="col" style="background-position:'+-(j*50)+'px '+-(i*50)+'px"></div>';
}
}
box.innerHTML=str;
for(var i=0;i<col.length;i++)
{
col[i].onmouseover=function(){
this.style.opacity="1";
this.style.filter="alpha(opacity:100)";
}
}
</script>
1.二维函数写法【效果展示】
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{margin:0;padding:0;}
body{background:#939393;}
#box{width:800px;height:800px;margin:0 auto;background:url(11.jpg);overflow: hidden;}
.col{width:50px;height:50px;outline:1px solid #fff;float:left;background:url(00.jpg) no-repeat;opacity:0;filter:alpha(opacity:0);}
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>
<script type="text/javascript">
var box=document.getElementById("box");
var rowDiv=[];
var tArray=new Array();
for(var i=0;i<16;i++) {
tArray[i] = new Array();
for (var j = 0; j < 16; j++) {
rowDiv[j] = document.createElement("div");
box.appendChild(rowDiv[j]);
rowDiv[j].className = "col";
tArray[i][j] = rowDiv[j];
var l = -(j * 50) + "px";
var T = -(i * 50) + "px";
tArray[i][j].style.backgroundPosition =l+" "+T;
tArray[i][j].onmouseover = function ()
{
this.style.opacity = "1";
this.style.filter="alpha(opacity:100)";
}
}
}
</script>
2.字符串写法【效果展示】
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{margin:0;padding:0;}
body{background:#939393;}
#box{width:800px;height:800px;margin:0 auto;background:url(11.jpg);overflow: hidden;}
.col{width:50px;height:50px;outline:1px solid #fff;float:left;background:url(00.jpg) no-repeat;opacity:0;filter:alpha(opacity:0);}
</style>
</head>
<script type="text/javascript" src="jquery-1.10.1.min.js"></script>
<body>
<div id="box"></div>
</body>
</html>
<script type="text/javascript">
var box=document.getElementById("box");
var col=box.getElementsByTagName("div");
var rowDiv=[];
var bg_P=[];
var str="";
for(var i=0;i<16;i++)
{
for(var j=0;j<16;j++)
{
str+='<div class="col" style="background-position:'+-(j*50)+'px '+-(i*50)+'px"></div>';
}
}
box.innerHTML=str;
for(var i=0;i<col.length;i++)
{
col[i].onmouseover=function(){
this.style.opacity="1";
this.style.filter="alpha(opacity:100)";
}
}
</script>
相关文章推荐
- exp/imp与expdp/impdp区别
- syslog及syslog-ng详解 日志服务器
- 第三周项目3—求集合并集
- 虚拟串口 vspd + C#2.0 测试串口 收发数据
- Git服务器 - 搭建git
- stackoverflow页面不正常
- jquery实现简单的选项卡功能
- ADO.NET的五个主要对象
- 流压缩技术 减少网络传输字节
- jQuery的deferred对象详解
- Android面试题总结
- tomcat 性能优化
- EF修改对象里面的值。。。(对象字段多的时候)
- Java正则表达式基础知识及实例说明
- 人们对Python在企业级开发中的10大误解
- 字符添加截取 超过8位自己截取,不够前面补0
- test4.7
- C#VS2010连接数据库大全
- android 代理地址
- cocos2d-js 使用过程中遇到的问题总结