Возможно, я не полно объяснил вопрос. Хочу понять, как скроллить без странного эффекта с пустым пространством:
Скрипт ниже вытворяет что то странное, поднимая саму страницу вверх (а внизу - пустое пространство)
В целом, я нашел рабочий скрипт:
let elements = document.querySelectorAll('.search-snippet-view');
if (elements.length > 0) {
let lastElement = elements[elements.length - 1];
lastElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
setTimeout(() => {
// Get the position of the last element
const lastElementRect = lastElement.getBoundingClientRect();
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
// Check if the last element is fully within the viewport
if (lastElementRect.bottom <= viewportHeight) {
// If the last element is fully in view, stop scrolling
return;
}
// If the last element is not fully in view, scroll down
window.scrollBy(0, 200);
}, 500); // Wait for the initial scroll to complete before scrolling down 200px
}
})();