mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: fix anchor with collapsible
This commit is contained in:
1 parent
f9cd5bcb40
commit
961bddb212
1 file changed
+13
-3
@@ -12,9 +12,19 @@ const smoothScrollPage = new AutoloadPage('smoothScrollPage', null, () => {
|
|||||||
if (!ANCHOR_REGEX.test(href)) return false;
|
if (!ANCHOR_REGEX.test(href)) return false;
|
||||||
const match = document.getElementById(href.slice(1));
|
const match = document.getElementById(href.slice(1));
|
||||||
if (!match) return false;
|
if (!match) return false;
|
||||||
|
const $content = $(match).closest('.collapsible-content');
|
||||||
|
if ($content.length && !$content.hasClass('expanded')) {
|
||||||
|
const $inner = $content.find('.collapsible-content__inner');
|
||||||
|
$inner.scrollTop(0);
|
||||||
|
$content.find('.collapsible-toggle__link').trigger('click');
|
||||||
|
$content.addClass('expanded');
|
||||||
|
$inner.css('max-height', 'none');
|
||||||
|
}
|
||||||
|
requestAnimationFrame(() => {
|
||||||
const rect = match.getBoundingClientRect();
|
const rect = match.getBoundingClientRect();
|
||||||
const anchorOffset = window.pageYOffset + rect.top - OFFSET_HEIGHT;
|
const anchorOffset = window.pageYOffset + rect.top - OFFSET_HEIGHT;
|
||||||
$('html,body').animate({ scrollTop: anchorOffset }, 200, 'easeOutCubic');
|
$('html,body').animate({ scrollTop: anchorOffset }, 200, 'easeOutCubic');
|
||||||
|
});
|
||||||
if (HISTORY_SUPPORT && pushToHistory) {
|
if (HISTORY_SUPPORT && pushToHistory) {
|
||||||
window.history.pushState({}, document.title, window.location.pathname + href);
|
window.history.pushState({}, document.title, window.location.pathname + href);
|
||||||
}
|
}
|
||||||
@@ -26,10 +36,10 @@ const smoothScrollPage = new AutoloadPage('smoothScrollPage', null, () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delegateAnchors(e) {
|
function delegateAnchors(e) {
|
||||||
if (e.metaKey || e.ctrlKey || e.shiftKey) return;
|
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
||||||
const elem = e.target;
|
const elem = e.target.closest('a');
|
||||||
if (
|
if (
|
||||||
elem.nodeName === 'A'
|
elem
|
||||||
&& scrollIfAnchor(elem.getAttribute('href'), true)
|
&& scrollIfAnchor(elem.getAttribute('href'), true)
|
||||||
) e.preventDefault();
|
) e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user