-4
$(window).on('scroll',function(){
});

How can I unbind this? I've tried .off, but that doesn't seem to work.

RobG
  • 124,520
  • 28
  • 153
  • 188
TIMEX
  • 217,272
  • 324
  • 727
  • 1,038

2 Answers2

1

I just tried it on this website, but I assigned the callback to a separate variable

var callback = function (data) {
    console.log(data);
}

$(window).on('scroll', callback);

and then to unset it

$(window).off('scroll', callback)
scrblnrd3
  • 6,366
  • 9
  • 31
  • 61
  • The OP is assigning a function expression (a so–called "anonymous function"), not a named function. How do you remove those? – RobG Aug 11 '14 at 01:09
0

Try doing it specifically for the handler.

scrollHandler = function() {
};

$(window).on('scroll', scrollHandler);
$(window).off('scroll', scrollHandler);
Amadan
  • 169,219
  • 18
  • 195
  • 256