<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<style type="text/css">
* {
padding: 0px;
margin: 0px;
}
.spandian {
background: black;
font-size: 0;
overflow: hidden;
2px;
height: 2px;
position: absolute;
}
</style>
</head>
<body>
<span class='spandian' id="spandian">.</span>
</body>
</html>
<script type="text/javascript">
$(function () {
var count = 10;//设置个数
for (var i = 1; i < count * 8; i++) {
$("#spandian").after("<span class='spandian'>.</span>");
}
})
//移动效果
window.document.onmousemove = function (e) {
e = event || e;
var left = e.clientX;
var top = e.clientY;
move(top, left);
}
//给每一个span定义位置
function move(top, left) {
$(".spandian").each(function () {
var len = 10 * 1;
var aqrt = Math.sqrt(2) * 1;
var index = $(this).index() * 1;
var indexJ = parseInt(index / 8) * 1 + 1;
var indexZ = parseInt(index % 8) * 1 + 1;
var mtop = indexZ == 1 || indexZ == 5 ? 0 : indexZ == 2 ? -indexJ * len / aqrt : indexZ == 3 ? -indexJ * len : indexZ == 4 ? -indexJ * len / aqrt : indexZ == 6 ? indexJ * len / aqrt : indexZ == 8 ? indexJ * len / aqrt : indexJ * len;
var mlef = indexZ == 3 || indexZ == 7 ? 0 : indexZ == 1 ? -indexJ * len : indexZ == 2 ? -indexJ * len / aqrt : indexZ == 4 ? indexJ * len / aqrt : indexZ == 5 ? indexJ * len : indexZ == 8 ? -indexJ * len / aqrt : indexJ * len / aqrt;
var ttop = mtop + top;
var llef = mlef + left;
var span = $(this)
setTimeout(function () { span.css({ top: ttop, left: llef }) }, index * 10)
})
}
</script>