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

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

RobG
  • 142,382
  • 31
  • 172
  • 209
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

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
  • 7,228
  • 9
  • 33
  • 64
  • 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
  • 191,408
  • 23
  • 240
  • 301