Skip to content

Commit

Permalink
scrolls
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaIa committed Jun 19, 2023
1 parent e662e17 commit e94e192
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ function onSubmitForm(event) {
};
if (data.totalHits > perPage) {
btnLoadMore.classList.remove('is-hidden');
window.addEventListener('scroll', showLoadMorePage);
};
// scrollPage();
})
.catch(onFetchError);

Expand All @@ -75,10 +77,33 @@ function onClickLoadMore() {
Notify.info("We're sorry, but you've reached the end of search results.", paramsForNotify);
};
lightbox.refresh();
// scrollPage();
})
.catch(onFetchError);
};

function onFetchError() {
Notify.failure('Oops! Something went wrong! Try reloading the page or make another choice!', paramsForNotify);
};

// function scrollPage() {
// const { height: cardHeight } = gallery.firstElementChild.getBoundingClientRect();

// window.scrollBy({
// top: cardHeight * 2,
// behavior: "smooth",
// });
// };

function showLoadMorePage() {
if (checkIfEndOfPage()) {
onClickLoadMore();
}
};

function checkIfEndOfPage() {
return (
window.innerHeight + window.scrollY >=
document.documentElement.scrollHeight
);
}

0 comments on commit e94e192

Please sign in to comment.