|
1 | | -<div class="map-wrap" markdown="0"> |
| 1 | +<style> |
| 2 | +.map-wrap { position: relative; display: block; width: 100%; } |
| 3 | + |
| 4 | +/* Your background map image */ |
| 5 | +.map-wrap img.basemap { width: 100%; display: block; } |
| 6 | + |
| 7 | +/* Each pin is absolutely positioned over the map */ |
| 8 | +.pin { |
| 9 | + position: absolute; |
| 10 | + cursor: pointer; |
| 11 | + transform: translate(-50%, -100%); /* anchor at the bottom-center of the dot */ |
| 12 | +} |
| 13 | + |
| 14 | +.pin-dot { |
| 15 | + width: 14px; height: 14px; |
| 16 | + border-radius: 50%; |
| 17 | + background: #e24b4a; |
| 18 | + border: 2.5px solid white; |
| 19 | + box-shadow: 0 1px 4px rgba(0,0,0,0.3); |
| 20 | + transition: transform 0.18s ease; |
| 21 | +} |
| 22 | +.pin:hover .pin-dot { transform: scale(1.6); } |
| 23 | + |
| 24 | +/* Tooltip balloon */ |
| 25 | +.tooltip { |
| 26 | + position: absolute; |
| 27 | + background: white; |
| 28 | + border: 1px solid #ddd; |
| 29 | + border-radius: 10px; |
| 30 | + padding: 10px 12px; |
| 31 | + width: 200px; |
| 32 | + bottom: calc(100% + 10px); /* sits above the pin */ |
| 33 | + left: 50%; |
| 34 | + transform: translateX(-50%) translateY(4px); |
| 35 | + opacity: 0; |
| 36 | + transition: opacity 0.18s ease, transform 0.18s ease; |
| 37 | + pointer-events: none; |
| 38 | + z-index: 100; |
| 39 | + box-shadow: 0 4px 12px rgba(0,0,0,0.12); |
| 40 | +} |
| 41 | +.pin:hover .tooltip { |
| 42 | + opacity: 1; |
| 43 | + transform: translateX(-50%) translateY(0); |
| 44 | +} |
| 45 | + |
| 46 | +/* Small image inside tooltip */ |
| 47 | +.tooltip img { width: 100%; border-radius: 6px; margin-bottom: 6px; } |
| 48 | +.tooltip h3 { margin: 0 0 4px; font-size: 14px; } |
| 49 | +.tooltip p { margin: 0; font-size: 12px; color: #666; } |
| 50 | + |
| 51 | +/* Tail triangle */ |
| 52 | +.tail { |
| 53 | + position: absolute; |
| 54 | + bottom: -6px; left: 50%; |
| 55 | + width: 10px; height: 10px; |
| 56 | + background: white; |
| 57 | + border-right: 1px solid #ddd; |
| 58 | + border-bottom: 1px solid #ddd; |
| 59 | + transform: translateX(-50%) rotate(45deg); |
| 60 | +} |
| 61 | +</style> |
| 62 | + |
| 63 | +<div class="map-wrap"> |
2 | 64 | <img class="basemap" src="/images/testmap.jpg" alt="World map" /> |
| 65 | + |
| 66 | + <!-- Pin: left/top are % of the map image dimensions --> |
3 | 67 | <div class="pin" style="left: 10%; top: 30%;"> |
4 | 68 | <div class="tooltip"> |
5 | 69 | <img src="/images/travels/lawncrush exp.png" alt="EXPERI" /> |
6 | 70 | <h3>Vancouver, Canada</h3> |
7 | | - <p>Testing an experiment idealsdfsoidfj dskfjjnsdfn sdkjfnsf can this fit?</p> |
| 71 | + <p>Testing an experiment idealsdfsoidfj |
| 72 | + dskfjjnsdfn |
| 73 | + sdkjfnsf |
| 74 | + can this fit? |
| 75 | + </p> |
8 | 76 | <div class="tail"></div> |
9 | 77 | </div> |
10 | 78 | <div class="pin-dot"></div> |
11 | 79 | </div> |
| 80 | + |
| 81 | + <div class="pin" style="left: 55%; top: 88%;"> |
| 82 | + <div class="tooltip"> |
| 83 | + <img src="/images/travels/NA" alt="Noimageaalttext" /> |
| 84 | + <h3>another place</h3> |
| 85 | + <p>second pin</p> |
| 86 | + <div class="tail"></div> |
| 87 | + </div> |
| 88 | + <div class="pin-dot"></div> |
| 89 | + </div> |
| 90 | + |
| 91 | + |
| 92 | + <!-- Add more pins here --> |
12 | 93 | </div> |
13 | 94 |
|
| 95 | + |
| 96 | + |
| 97 | +<!-- extra bit for mobile click/hover functionality --> |
14 | 98 | <script> |
15 | 99 | document.querySelectorAll('.pin').forEach(pin => { |
16 | 100 | pin.addEventListener('click', function(e) { |
17 | 101 | e.stopPropagation(); |
| 102 | + // Close any other open pins first |
18 | 103 | document.querySelectorAll('.pin.active').forEach(p => { |
19 | 104 | if (p !== pin) p.classList.remove('active'); |
20 | 105 | }); |
| 106 | + // Toggle this one |
21 | 107 | pin.classList.toggle('active'); |
22 | 108 | }); |
23 | 109 | }); |
| 110 | + |
| 111 | +// Tap anywhere else on the map to close all tooltips |
24 | 112 | document.addEventListener('click', () => { |
25 | 113 | document.querySelectorAll('.pin.active').forEach(p => p.classList.remove('active')); |
26 | 114 | }); |
|
0 commit comments