<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#div1 {
width: 509px;
height: 509px;
position: relative;
background-color: #ccc;
}
.box {
position: absolute;
width: 50px;
height: 50px;
margin-top: 1px;
}
</style>
</head>
<body>
<div id="div1" style="">
</div>
<script>
var oDiv = document.getElementById('div1');
for( var i=0;i<100;i++ ){
oDiv.innerHTML += '<div class="box">'+'</div>';
}
var aDiv = oDiv.getElementsByTagName('div');
for(var i=0;i<100;i++){
if(i%10==0){
var j = 0;
aDiv[i].style.top = (5.1*i) + 'px';
var tempt = (5.1*i) + 'px';
aDiv[i].style.left = (j-1)+'px';
aDiv[i].style.backgroundPositionX = '-'+j+'px'
aDiv[i].style.backgroundPositionY = '-'+(5.1*i) + 'px';
} else {
aDiv[i].style.top = tempt;
aDiv[i].style.left = j*51+'px';
aDiv[i].style.backgroundPositionX = '-'+j*51+'px';
aDiv[i].style.backgroundPositionY = '-'+tempt;
}
j++;
aDiv[i].onmouseover = function () {
this.style.backgroundImage = 'url(http://i2.bvimg.com/620364/508fbf8b47365fbc.jpg)';
}
}
</script>
</body>
</html>