2011-05-05 127 views
3

我想使用圖像地圖的座標,但不是地圖本身。所以我的問題是我可以使用圖像地圖的座標,並檢測用戶是否使用jQuery滾動這些座標?有沒有辦法在jQuery中使用圖像地圖座標?

編輯:

我的目標是這樣的:(不實際使用圖像映射,只是它的coords)使用

從影像地圖座標:186,106,199,86,220,86,241,94,245,109

$("img#test").hover(function(e) { 
     if (e.pageX >= 186 && e.pageY >= 106 && 
      e.pageX >= 199 && e.pageY >= 86 && 
      e.pageX >= 220 && e.pageY >= 86 && 
      e.pageX >= 241 && e.pageY >= 94 && 
      e.pageX >= 245 && e.pageY >= 109) 
      alert("wewt"); 
    }); 

回答

3

您可以直接或使用jQuery將事件偵聽器添加到標記。例如:

<map name="testmap" id="testmap"> 
    <area shape="rect" coords="10,9,58,27" href="#" title="" alt="You are on a rectangle!"> 
    <area shape="circle" coords="104,18,14" href="#" title="" alt="You are on a circle!"> 
</map> 
<img src="/img/image.png" style="width:136px;height:36px" usemap="#testmap" /> 

<script type="text/javascript"> 
    $('#testmap area').mouseover(function() 
    { 
     alert($(this).attr("alt")); 
    }); 
</script> 
+0

示例:http://jsfiddle.net/pxfunc/aVDHW/ – MikeM 2011-05-05 16:57:00

+0

爲什麼要編輯它?我沒有看到需要使用jQuery來閱讀alt屬性! – 2011-05-06 05:23:28

+0

好點,'this.alt'比'$(this).attr(「alt」)更優化' – MikeM 2011-05-06 14:49:34

相關問題