Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How to put a delay

anuraa

Legendary Coder
JavaScript:
<script>
    var lastScrollTop = 0;
    window.addEventListener("scroll", function(){
    var st = window.pageYOffset || document.documentElement.scrollTop;
    if (st > lastScrollTop){
       closeNav();
    } else {
       delay(3000);
       openNav();
    }
    lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling
 }, false);
 </script>

Hello friends: This is related to webpage overlay window. openNav() and closeNav opens/closes the ovelay window.
With the above code with scrolling, the window opens/Closes. I added delay(3000); to delay the opening of the window. With that addition,
it doesn't even open now.
1. I want to accomplish the opening a with a bit delay in case of scrolling.
2. Is it possible to add the transition delay further here too

Thanks

Anura
 
document.getElementById("sidenav").style.transitionDelay = "1s";

This code worked.
Good that you found this solution, because there is no built-in delay command in JavaScript. Rather inconvenient but it's because of the asynchronous design of JS. You need to use a promise and an async function, but by understanding of these concepts were insufficient to advise you.
 
Good that you found this solution, because there is no built-in delay command in JavaScript. Rather inconvenient but it's because of the asynchronous design of JS. You need to use a promise and an async function, but by understanding of these concepts were insufficient to advise you.
Thanks for the explanation. I tried with setTimeout() too, to see not working. Regards Anura
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom