How to programmatically disable page scrolling with jQuery

后端 未结 23 2316
滥情空心
滥情空心 2020-11-22 08:09

Using jQuery, I would like to disable scrolling of the body:

My idea is to:

  1. Set body{ overflow: hidden;}
  2. Capture the current
23条回答
  •  [愿得一人]
    2020-11-22 08:38

    This will completely disable scrolling:

    $('html, body').css({
        overflow: 'hidden',
        height: '100%'
    });
    

    To restore:

    $('html, body').css({
        overflow: 'auto',
        height: 'auto'
    });
    

    Tested it on Firefox and Chrome.

提交回复
热议问题