How to disable scrolling temporarily?

前端 未结 30 2467
萌比男神i
萌比男神i 2020-11-21 05:16

I\'m using the scrollTo jQuery plugin and would like to know if it is somehow possible to temporarily disable scrolling on the window element through Javascript? The reason

30条回答
  •  梦毁少年i
    2020-11-21 05:18

    I'm using showModalDialog, for showing secondary page as modal dialog.

    to hide main window scrollbars:

    document.body.style.overflow = "hidden";
    

    and when closing modal dialog, showing main window scrollbars:

    document.body.style.overflow = "scroll";
    

    to access elements in main window from dialog:

    parent.document.getElementById('dialog-close').click();
    

    just for anybody searching about showModalDialog:(after line 29 of original code)

    document.getElementById('dialog-body').contentWindow.dialogArguments = arg;
    document.body.style.overflow = "hidden";//****
    document.getElementById('dialog-close').addEventListener('click', function(e) {
        e.preventDefault();
        document.body.style.overflow = "scroll";//****
        dialog.close();
    });
    

提交回复
热议问题