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.

Tschitsch
  • 1,253
  • 8
  • 18
user3539644
  • 3
  • 1
  • 5
  • Just check if its changed from a global var and if so snap back to global var. – WASasquatch Apr 17 '14 at 06:46
  • possible duplicate of [how to disable scrollbar without overflow:hidden in jQuery](http://stackoverflow.com/questions/7379032/how-to-disable-scrollbar-without-overflowhidden-in-jquery) – Pratik Joshi Apr 17 '14 at 06:57

2 Answers2

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/

Community
  • 1
  • 1
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
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.

WASasquatch
  • 1,044
  • 3
  • 11
  • 19