fix: fixed auto scroll on url examples on link tracking page

This commit is contained in:
Leyla Becker 2026-02-19 11:47:16 -06:00
parent 3701dbe3db
commit cb47c11a14

View file

@ -194,19 +194,21 @@ TODO: explain why that is a bad thing for privacy, and personal life
<script> <script>
(function() { (function() {
const urlExample = document.querySelector('.url-example');
const legendItems = document.querySelectorAll('.url-legend-item[data-part]'); const legendItems = document.querySelectorAll('.url-legend-item[data-part]');
legendItems.forEach(item => { legendItems.forEach(item => {
item.addEventListener('mouseenter', () => { item.addEventListener('mouseenter', () => {
const part = item.dataset.part; const part = item.dataset.part;
const urlPart = document.querySelector(`.url-example [data-part="${part}"]`); const urlPart = document.querySelector(`.url-example [data-part="${part}"]`);
if (urlPart && urlExample) { if (urlPart) {
const containerRect = urlExample.getBoundingClientRect(); const urlExample = urlPart.closest('.url-example');
const partRect = urlPart.getBoundingClientRect(); if (urlExample) {
const partCenter = partRect.left - containerRect.left + urlExample.scrollLeft + (partRect.width / 2); const containerRect = urlExample.getBoundingClientRect();
const scrollTarget = partCenter - (containerRect.width / 2); const partRect = urlPart.getBoundingClientRect();
urlExample.scrollTo({ left: scrollTarget, behavior: 'smooth' }); const partCenter = partRect.left - containerRect.left + urlExample.scrollLeft + (partRect.width / 2);
const scrollTarget = partCenter - (containerRect.width / 2);
urlExample.scrollTo({ left: scrollTarget, behavior: 'smooth' });
}
} }
}); });
}); });