js/css : disable scrollbar but keep scroll position

后端 未结 6 458
情深已故
情深已故 2020-12-31 01:40

I\'m using the Jquery dialog to open a popup box window on top of a page. When I open the dialog box, I want the general page scrolling to be disabled. To do so, I am doing

6条回答
  •  时光取名叫无心
    2020-12-31 01:58

    you can calculate the difference between the body width, before and after the overflow hidden, and apply it as padding-right to the body

    var bodyStartW = $("body").width();
    $("body").css("overflow-y" , "hidden");
    var bodyEndW = $("body").width();
    var bodyMarginL = bodyEndW - bodyStartW;
    $("body").css("padding-right" , bodyMarginL);
    

    In Safari you had the same trick for the "html" tag, and margin-right instead of padding-right

提交回复
热议问题