0

In a html page i am calling a function at window scroll down in some cases i dosen't want to call window scroll down event(function) then how can i dsable window scroll down event. am using code:

$(window).scroll(function(){
    var wintop = $(window).scrollTop(), 
        docheight = $(document).height(), 
        winheight = $(window).height();
    var scrolltrigger = 0.95;
    if  ((wintop/(docheight-winheight)) > scrolltrigger) {
        //console.log('scroll bottom');
        add();
    }
});

Please help me if any one knows solution.

2

2 Answers 2

2

Use following code

$('body').on({
'mousewheel': function(e) {
    if (e.target.id == 'el') return;
    e.preventDefault();
    e.stopPropagation();
    }
})

You get good answer here -> jQuery or Javascript - how to disable window scroll without overflow:hidden;

Live demo http://jsfiddle.net/92mxb/

Sign up to request clarification or add additional context in comments.

Comments

0

Just do something like this to snap back to origin. Something similar too this inside the scroll() function

if ( initScrollTop != $(window).scrollTop() ) {
    $(window).scrollTop( initScrollTop );
}

With the global being declared outside the function.

 var initScrollTop = $(window).scrollTop();

I'm on my phone and cannot test. Will be home soon, but it should be nearly that simple.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.