I am working on my portfolio and for that I want to apply delay on my link for which i am using setTimeOut function but the problem is when I am trying to wrap the EventListener in a function and call this setTimeOut function whether inside or outside it is not working.
Please go through the code for better understanding of my problem.
//------ NOT WORKING (Outside EventListener) ------//
function firstLink(){
HomePageH.addEventListener('click', ()=> {
window.location.href = '../index.html';
})
}
function secondLink(){
AboutMeH.addEventListener('click', ()=> {
window.location.href = rootURL + '#about-me';
})
}
function thirdLink(){
WorksIDoH.addEventListener('click', ()=> {
window.location.href = rootURL + '#work-i-do';
})
}
setTimeout(() => {
firstLink();
secondLink();
thirdLink();
}, waitTime);
//------ NOT WORKING (Inside EventListener) ------//
HomePageH.addEventListener('click', ()=> {
function firstLink(){
window.location.href = '../index.html';
}
})
AboutMeH.addEventListener('click', ()=> {
function secondLink(){
window.location.href = rootURL + '#about-me';
}
})
WorksIDoH.addEventListener('click', ()=> {
function thirdLink(){
window.location.href = rootURL + '#work-i-do';
}
})
setTimeout(() => {
firstLink();
secondLink();
thirdLink();
}, waitTime);
//------ WORKING CODE (But have to apply timeout again and again) ------//
HomePageH.addEventListener('click', ()=> {
setTimeout(() => {
window.location.href = '../index.html';
}, waitTime);
});
AboutMeH.addEventListener('click', ()=> {
setTimeout(() => {
window.location.href = rootURL + '#about-me';
}, waitTime);
});
WorksIDoH.addEventListener('click', ()=> {
setTimeout(() => {
window.location.href = rootURL + '#work-i-do';
}, waitTime);
});