Search code examples
javascriptjquerypreloader

Stop JavaScript function after 3 seconds


Heyo,

I want to call a function that disables the scrollwheel while the Preloader is shown. But after the Preloader is gone, the scrollwhell should be usable again. I got the function which disables the scrollwheel allready. Now I need a simple code which makes it run only the first 3 seconds.

My anitscrollwheel function looks like so: window.onwheel = function(){ return false; }


Solution

  • Try this:

    <script type="text/javascript">
        var wheelEnabled = false;
    
        window.onwheel = function() { return wheelEnabled; }
    
        setTimeout(function() {
            wheelEnabled = true;
        }, 3000);
    </script>