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

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

RobG
  • 134,457
  • 30
  • 163
  • 204
TIMEX
  • 238,746
  • 336
  • 750
  • 1,061

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,725
  • 9
  • 32
  • 63
  • 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
  • 179,482
  • 20
  • 216
  • 275