fix: fixed auto scroll on url examples on link tracking page
This commit is contained in:
parent
3701dbe3db
commit
cb47c11a14
1 changed files with 9 additions and 7 deletions
|
|
@ -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' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue