Skip to content

Commit

Permalink
Merge pull request #15 from boriskrasko/markup
Browse files Browse the repository at this point in the history
Map zoom
  • Loading branch information
boriskrasko authored Feb 22, 2024
2 parents f276e44 + fe2b982 commit a310843
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ const mapImage = document.querySelector('.map-svg svg');
let width = 1;
document.querySelector('.map-svg').addEventListener('wheel', (event) => {
event.preventDefault();
const rect = mapImage.getBoundingClientRect();
const mouseX = event.clientX - rect.left;
const mouseY = event.clientY - rect.top;
const offsetX = mouseX / rect.width;
const offsetY = mouseY / rect.height;
width += event.deltaY * -0.01;
width = Math.min(Math.max(0.5, width), 4);
mapImage.style.width = `${width * 1000}px`;
const newRect = mapImage.getBoundingClientRect();
mapImage.style.left = `${parseFloat(mapImage.style.left) - (newRect.width - rect.width) * offsetX}px`;
mapImage.style.top = `${parseFloat(mapImage.style.top) - (newRect.height - rect.height) * offsetY}px`;
});

function getCoords(elem) {
Expand Down Expand Up @@ -283,7 +291,6 @@ document.querySelector('.zoom-out').addEventListener('click', () => {
zoom('out');
});


bookmarkCountyList.querySelectorAll('li').forEach(item => {
item.addEventListener('click', handleCountryClick);
})
Expand Down

0 comments on commit a310843

Please sign in to comment.