Pelle2010
Pelle2010

Reputation: 143

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; }

Upvotes: 1

Views: 3215

Answers (2)

BlakSneil
BlakSneil

Reputation: 206

Try this:

<script type="text/javascript">
    var wheelEnabled = false;

    window.onwheel = function() { return wheelEnabled; }

    setTimeout(function() {
        wheelEnabled = true;
    }, 3000);
</script>

Upvotes: 1

Ali Zia
Ali Zia

Reputation: 3875

You can do something like that

var enable_scroll = false;

//When preloader ends, set enable_scroll = true;

window.onwheel = function(){
    if(enable_scroll == false) {
        return false; 
    }
}

Upvotes: 0

Related Questions