Reputation: 359
I have one big image (let's say it's a map) and multiple smaller images (points on the map) that are shown on this image on hover event. Currently I'm positioning smaller images with position: absolute
but when I got to the point where the screen width forces my big image to resize, smaller images are not placed where I want them to be. How can I make this work using CSS and not making this images too big so the user can hover only on the exact image I want them to hover?
Upvotes: 1
Views: 54
Reputation: 5992
var startWidth = 0;
document.addEventListener('DOMContentLoaded', function () {
var el = document.getElementById("the-img");
startWidth = el.offsetWidth;
// use offSetWidth & offSetHeight to get the dimension of your smaller image(s)
}
window.addEventListener('resize', getRatio);
function getRatio(){
var el = document.getElementById("the-img");
ratio = startWidth/el.offsetWidth;
var smallerImgWid = ratio * orginialSmallImgWid;
var smallerImgHeigh = ratio * origonalSmallImgHeight;
}
Upvotes: 2