62,623
社区成员
发帖
与我相关
我的任务
分享
<style>
img{position:absolute;width:1px;height:1px;background:red}
</style>
<BODY>
<div style="position:absolute;width:302px;height:202px;border:1px solid red;background:#FFFFFF" onclick="getArea(event);">
<script>
for(var i=0;i<300;i++){
document.write("<img style='left:" + i + "px;top:" + Math.floor(i*200/300) + "px;'>")
document.write("<img style='left:" + i + "px;top:" + (200-Math.floor(i*200/300)) + "px;'>")
}
</script>
</div>
<script>
function getArea(e){
var width = 300;
var height = 200;
var x = e.offsetX;
var y = e.offsetY;
var line1 = width*y - height*x; //对角线1方程
var line2 = width*y + height*x - height*width; //对角线2方程
if(line1>0){
if(line2 > 0){
alert("下面区域");
}else if(line2 < 0){
alert("左面区域");
}
}
if(line1<0){
if(line2 > 0){
alert("右面区域");
}else if(line2 < 0){
alert("上面区域");
}
}
}
</script>
</BODY>