是否可以制作完全自定义的网站布局?如果可能,最好在javascript/dhtml中。我正在做一个鼹鼠游戏,我希望用户能够定位网页上任何地方出现痣的洞。我当前的代码是草率的,因为我只是尝试,就如何做到这一点,但我当前的代码是完全可自定义的布局?
<html>
<body>
<!--CURSOR-->
<style type="text/css">
body, a, a:hover {cursor: url(http://cur.cursors-4u.net/others/oth-5/oth438.cur),
progress;}
</style>
<!--BACKGROUND-->
<body background = "http://i52.tinypic.com/34e9ekj.jpg">
<!--COUNTER(needs to be implemnted)-->
<b><center><font size="5"><div id='counter'>0</div></font></center><b>
<!--TITLE-->
<b><center><i>Whack-A-Mole</i> - by Steven</center></b>
<!--HOLE IMAGES START HERE-->
<!--Hole 1 Row 1-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:33px;margin-top:3px;position:absolute"/>
<!--Hole 2 Row 1-->
<img src="http://i51.tinypic.com/sxheeo.gif" style="margin-left:350px;margin-top:3px;position:absolute"/>
<!--Hole 3 Row 1-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:700px;margin-top:3px;position:absolute"/>
<!--Hole 4 Row 2-->
<img src="http://i51.tinypic.com/sxheeo.gif" style="margin-left:33px;margin-top:160px;position:absolute"/>
<!--Hole 5 Row 2-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:350px;margin-top:160px;position:absolute"/>
<!--Hole 6 Row 2-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:700px;margin-top:160px;position:absolute"/>
<!--Hole 7 Row 3-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:33px;margin-top:310px;position:absolute"/>
<!--Hole 8 Row 3-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:350px;margin-top:310px;position:absolute"/>
<!--Hole 9 Row 3-->
<img src ='http://i51.tinypic.com/sxheeo.gif' style="margin-left:700px;margin-top:310px;position:absolute"/>
<!--HOLE IMAGES END HERE-->
<!--MOLE DIVS START HERE-->
<!--Mole 1 Row 1-->
<div id="randomdiv1"
class="mole">
<img src="http://i56.tinypic.com/2i3tyw.gif" style="margin-left:33px;margin-top:3px;position:absolute"/>
</div>
<!--Mole 2 Row 1-->
<div id="randomdiv2"
class="mole">
<img id="Mole1" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:350px;margin-top:3px;position:absolute"/>
</div>
<!--Mole 3 Row 1-->
<div id="randomdiv3"
class="mole">
<img id="Mole2" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:700px;margin-top:3px;position:absolute"/>
</div>
<!--Mole 4 Row 2-->
<div id="randomdiv4"
class="mole">
<img id="Mole3" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:33px;margin-top:160px;position:absolute"/>
</div>
<!--Mole 5 Row 2-->
<div id="randomdiv5"
class="mole">
<img id="Mole4" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:350px;margin-top:160px;position:absolute"/>
</div>
<!--Mole 6 Row 2-->
<div id="randomdiv6"
class="mole">
<img id="Mole5" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:700px;margin-top:160px;position:absolute"/>
</div>
<!--Mole 7 Row 3-->
<div id="randomdiv7"
class="mole">
<img id="Mole6" src="http://i56.tinypic.com/2i3tyw.gif" style="margin-left:33px;margin-top:310px;position:absolute"/>
</div>
<!--Mole 8 Row 3-->
<div id="randomdiv8"
class="mole">
<img id="Mole8" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:350px;margin-top:310px;position:absolute"/>
</div>
<!--Mole 9 Row 3-->
<div id="randomdiv9"
class="mole">
<img id="Mole9" src ='http://i56.tinypic.com/2i3tyw.gif' style="margin-left:700px;margin-top:310px;position:absolute"/>
</div>
</body>
<!--MOLE DIVS END HERE-->
<head>
<script type="text/javascript" language="JavaScript">
<!--
// Type the number of div containers to randomly display below.
NumberOfDivsToRandomDisplay = 9;
var CookieName = 'DivRamdomValueCookie';
function DisplayRandomDiv() {
var r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay);
if(NumberOfDivsToRandomDisplay > 1) {
var ck = 0;
var cookiebegin = document.cookie.indexOf(CookieName + "=");
if(cookiebegin > -1) {
cookiebegin += 1 + CookieName.length;
cookieend = document.cookie.indexOf(";",cookiebegin);
if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
ck = parseInt(document.cookie.substring(cookiebegin,cookieend));
}
while(r == ck) { r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay); }
document.cookie = CookieName + "=" + r;
}
for(var i=1; i<=NumberOfDivsToRandomDisplay; i++) {
document.getElementById("randomdiv"+i).style.display="none";
}
<!--Make counter +1 on mole click-->
document.getElementById("randomdiv"+r).onclick = function() {
counter.innerHTML = parseInt(counter.innerHTML) + 1;
}
document.getElementById("randomdiv"+r).style.display="block";
}
<!--Make moles pop up randomly on a timer-->
DisplayRandomDiv()
setInterval("DisplayRandomDiv()",(Math.random()*500) + 1000);
//-->
</script>
</head>
</html>
我不知道,如果它甚至有可能或没有,但咩,不妨问。 :) 谢谢!
我有点得到你的意见,但实际上是否允许最终用户拖动他们想要的洞? – Steven
@Steven:您对使用jQuery-UI或类似的库感觉如何?我不会推荐用手拖动。用于drag'n'drop的jQuery-UI,用于跟踪事物的Cookie以及恰当的CSS定位应该能够完成工作。 –