0
我覺得我是如此接近找出這一點,但錯過了一些東西......我試圖定位多個div上面和多個矩形區域形狀的左側位置上我圖像映射。一切都追溯到我的控制檯,但它沒有設置頂部和左側的位置到divpositon div上面區域形狀頂部和左側位置與jquery
以下是我迄今爲止,但感覺我失去了一些東西..任何將是一個生命的救星!
圖像映射:
<img id="map" src="assets/img/header_bg2.png" width="1345" height="534" border="0" usemap="#neighbormap" />
<map name="neighbormap" id="neighbormap">
<areaclass="button" data-target="one" shape="rect" coords="335,239,376,282" href="#" />
<area class="button" data-target="two" shape="rect" coords="401,116,438,155" href="#" />
<area class="button" data-target="three" shape="rect" coords="493,7,536,42" href="#" />
</map>
Div的需要被置於上述頂部和左側的區域形狀的位置:
<div class="container">
<div class="one">one</div>
<div class="two">two</div>
<div class="three">three</div>
</div>
Jquery的:
$('#neighbormap').find('.button').each(function(index, element){
var i, x = [], y = [];
var c = $(this).attr('coords').split(',');
var id = $(this).data('target')
for (i=0; i < c.length; i++){
x.push(c[i++]);
y.push(c[i]);
}
var t = y.sort(num)[0];
var l = x.sort(num)[0];
$('.' + id).css({top: t, left: l, position:'absolute'});
//console.log(t + ',' + l);
function num(a, b){ return (a-b);
}
})
UPDATE:
我是missi NG 「PX」 應該是這樣的:
$('.' + id).css({top : t +'px',left : l +'px'});