(function () {
adjust ()
var timer = null
window.onresize = function () {
clearTimeout(timer)
timer = setTimeout( function () {
window.location.reload()
}, 100)
}
//重新设置每个热区
function adjust () {
var areas = $('#planetmap').children()
$.each(areas, function (idx, ele) {
var oldCoords = $(ele).attr('coords');
console.log(oldCoords)
$(ele).attr('coords', adjustPosition(oldCoords) );
})
}
//坐标转换
function adjustPosition (pos) {
var docWidth = $('body').width(),
docHeight = $('body').height(),
imageWidth = 700,
imageHeight = 1000;
var coords = pos.split(',');
for (var i = 0; i < coords.length; i++) {
coords[i] = Math.floor( parseInt(coords[i]) * docWidth / imageWidth ).toString();
i++;
coords[i] = Math.floor( parseInt(coords[i]) * docHeight / imageHeight ).toString();
}
console.log(coords.join(','))
return coords.join(',')
}
})()