这样能否得到你的5C币???
<html>
<head>
<style>
#you {
background:yellow;
position:absolute;
height:100px;
width:100px;
}
</style>
<script>
window.onload=function ()
{
function getElementsByClassName(object,classname)
{
var oObject = document.getElementsByTagName(object);
var re = [];
for (var i = 0;i < oObject.length;i++)
{
if (oObject[i].className = classname)
{
re.push(oObject[i]);
}
}
return re;
}
var oYou = document.getElementById("you");
var oDi = getElementsByClassName("div","di");
document.onmousemove=function (ev)
{
oEv = ev||event
var l = oYou.style.left;
var r = oYou.style.top;
if (l < 0)
{
l = 0;
}
else if (r < 0)
{
r = 0;
alert("You are win!")
}
else if (l > document.documentElement.clientWidth-oYou.offsetWidth)
{
l = document.documentElement.clientWidth-oYou.offsetWidth;
}
else if (r >document.documentElement.clientHeight-oYou.offsetHeight)
{
r = document.documentElement.clientHeight-oYou.offsetHeight;
}
else
{
oYou.style.top=oEv.clientY;
oYou.style.left=oEv.clientX;
}
for (var i = 0;i < oDi.length;i++)
{
oDi[i].style.left = oDi[i].offsetLeft + 1 + "px";
/*alert(oDi[i].id);*/
}
}
}
</script>
</head>
<body>
<div id="you"></div>
<div style="background:red;position:absolute;height:200px;width:300px;left:0px;top:0%;" id="di1" class="di"></div>
<div style="background:red;position:absolute;height:200px;width:300px;left:0px;top:10%;" id="di2" class="di"></div>
<div style="background:red;position:absolute;height:200px;width:300px;left:0px;top:20%" id="di3" class="di"></div>
<div style="background:red;position:absolute;height:200px;width:300px;left:0px;top:30%" id="di4" class="di"></div>
</body>
</html>
|