X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/fdd34a74eddb114aec8b2f6343dafcd49605b7f1..refs/pull/1646/head:/resources/assets/js/services/util.js diff --git a/resources/assets/js/services/util.js b/resources/assets/js/services/util.js index 727c723c6..b2f291872 100644 --- a/resources/assets/js/services/util.js +++ b/resources/assets/js/services/util.js @@ -24,4 +24,25 @@ export function debounce(func, wait, immediate) { timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; -}; \ No newline at end of file +}; + +/** + * Scroll and highlight an element. + * @param {HTMLElement} element + */ +export function scrollAndHighlightElement(element) { + if (!element) return; + element.scrollIntoView({behavior: 'smooth'}); + + const color = document.getElementById('custom-styles').getAttribute('data-color-light'); + const initColor = window.getComputedStyle(element).getPropertyValue('background-color'); + element.style.backgroundColor = color; + setTimeout(() => { + element.classList.add('selectFade'); + element.style.backgroundColor = initColor; + }, 10); + setTimeout(() => { + element.classList.remove('selectFade'); + element.style.backgroundColor = ''; + }, 3000); +} \ No newline at end of file