I would like to know how to disable a function in the code after clicking a button, and reactivating it after clicking on another one.
Here is what I’m trying to do :
I have an infinite loading script on a repeater page, so as the user scrolls down, it will automatically load more items
I have a ‘go to top’ button and a ‘go to footer’ button
I want the user to be able to access the footer if he clicks the ‘go to footer’ button, by doing so, it needs to disable the infinite loading script
The infinite loading function would be enabled again as the users exits the footer
Here is the infinite loading script (triggered everytime the user reaches the line under the repeater)
export function line12_viewportEnter(event, $w) {
//shows 'loading more items' text message
$w('#text73').show();
//automaticly loads more items upon reaching the bottom of the page
$w("#dynamicDataset").loadMore()
.then( () => {
console.log("Done loading more data");
});
}
Hi,
How about creating a boolean global variable and insert it as condition the function that loads more data from the dataset.
let loadMore = true;
function scrollDown() {
loadMore = false;
scrollToFooter();
setTimeout(() => {
loadMore = true;
},2000);
}
export function line12_viewportEnter(event, $w) {
//shows 'loading more items' text message
if (loadMore) {
$w('#text73').show(); //automaticly loads more items upon reaching the bottom of the page
$w("#dynamicDataset").loadMore()
.then( () => {
console.log("Done loading more data");
});
}
}
//goes to footer upon clicking the button and disables autolaod
let loadMore = true;
export function button33_click(event, $w) {
loadMore = false;
wixWindow.scrollTo(0, 9999);
setTimeout(() => {
loadMore = true;
},2000);
}
export function line12_viewportEnter(event, $w) {
//automaticly loads more items upon reaching the bottom of the page
if (loadMore) {
//shows loading message and then loads more items
$w('#text73').show();
$w("#dynamicDataset").loadMore()
.then( () => {
console.log("Done loading more data");
//hides 'loading more' text message after successful loading
$w('#text73').hide();
});
}
else {
//hides the 'loading more' message if there is no item left to load
// I couldn't find a way to display a "no more results found message
//instead
$w('#text73').hide();
}
}
Just one comment Roi, what is the setTimeOut purpose here ?