jQuery bind/unbind 'scroll' event on $(window)

后端 未结 6 784
梦谈多话
梦谈多话 2020-12-08 13:30

I have this function:

function block_scroll(key){
    if (key) {
        $(window).bind(\"scroll\", function(){
            $(\'html, body\').animate({scrol         


        
相关标签:
6条回答
  • 2020-12-08 13:46

    try this:

    $(window).unbind('scroll');
    

    it works in my project

    0 讨论(0)
  • 2020-12-08 13:52

    Note that the answers that suggest using unbind() are now out of date as that method has been deprecated and will be removed in future versions of jQuery.

    As of jQuery 3.0, .unbind() has been deprecated. It was superseded by the .off() method since jQuery 1.7, so its use was already discouraged.

    Instead, you should now use off():

    $(window).off('scroll');
    
    0 讨论(0)
  • 2020-12-08 13:55
    $(window).unbind('scroll');
    

    Even though the documentation says it will remove all event handlers if called with no arguments, it is worth giving a try explicitly unbinding it.

    Update

    It worked if you used single quotes? That doesn't sound right - as far as I know, JavaScript treats single and double quotes the same (unlike some other languages like PHP and C).

    0 讨论(0)
  • 2020-12-08 13:55

    Try this instead

    $.unbind('scroll');
    

    http://api.jquery.com/unbind/

    0 讨论(0)
  • 2020-12-08 13:56

    You need to:

    unbind('scroll')
    

    At the moment you are not specifying the event to unbind.

    0 讨论(0)
  • 2020-12-08 14:00

    Very old question, but in case someone else stumbles across it, I would recommend trying:

    $j("html, body").stop(true, true).animate({
            scrollTop: $j('#main').offset().top 
    }, 300);
    
    0 讨论(0)
提交回复
热议问题