JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test">
<input type="image" src="http://www.4x4hits.com/img/surfbar/1n89yb3b48bfj8uhdg6gysii_inr76ghbg987wbv3454.gif" style="border: 1px solid #000000;" width="200" height="50" border="0">
</div>
CSS
#test {
overflow: hidden;
position: relative;
}
#test a {
content: "";
z-index: 10;
position: absolute;
top: 0px;
background: rgba(0,0,0,0.2);
}
#test a:hover {
background: transparent;
}
JavaScript
var p = document.getElementById('test');
var m = p.getElementsByTagName('input')[0];
var w = m.offsetWidth;
var h = m.offsetHeight;
var a = p.getElementsByTagName('a');
var l = [
'http://povezava-1.com',
'http://povezava-2.com',
'http://povezava-3.com',
'http://povezava-4.com'
];
// Stili za parent element
p.setAttribute('style', 'max-width:' + w + 'px; max-height:' + h + 'px;');
// Dodajanje linkov in stilov
for (i = 0; i < l.length; i++) {
p.innerHTML = p.innerHTML + '<a href="' + l[i] + '" target="_blank"></a>';
a[i].setAttribute('style', 'width:' + w / l.length + 'px; height:' + h + 'px; left:' + w / l.length * i + 'px;');
}
// SporoÄŤilo ob kliku
for (i = 0; i < a.length; i++) {
(function(index) {
p.children[i + 1].onclick = function(e) {
alert('Kliknil si sliko ' + (index + 1));
e.preventDefault();
}
})(i);
}