<style type="text/css">
#field
{
width:500px;
height:500px;
border:1px solid black;
}
.Ninjaimg
{
position:absolute;
width:30px;
height:30px;
display:none;
cursor:pointer;
}
.circlle
{
width: 150px;
height: 150px;
-moz-border-radius: 50%;
border-radius: 50%;
border:1px solid black;
position: relative;
z-index: 1;
display:none;
}
</style>
<script type="text/javascript">
function makeNewPosition() {
// Get viewport dimensions (remove the dimension of the div)
var h = $("#field").height() - 30;
var w = $("#field").width() - 30;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh, nw];
}
$("#Start").click(function () {
var newq1 = makeNewPosition();
var newq2 = makeNewPosition();
$("#ninjaimage1").css("display", "block");
$("#ninjaimage1").animate({ top: newq1[0], left: newq1[1] });
$("#ninjaimage2").css("display", "block");
$("#ninjaimage2").animate({ top: newq2[0], left: newq2[1] });
// $(this).attr("disabled","disabled");
});
</script>
<div id="field" >
<img src="ninja.png" id="ninjaimage1" class="Ninjaimg" />
<img src="img1.jpg" id="ninjaimage2" class="Ninjaimg" />
<div id="cirlce1" class="circlle"></div>
<div id="cirlce2" class="circlle"></div>
</div>
<input type="button" id="Start" value="startGame" />
当我点击startgame时,两个图像占据div内的随机位置我的问题是,当两个图像占据他们的位置时,我想将两个圆圈定位在他们的中心是图像本身的条件下