If Thickbox is opened set body noscroll

安稳与你 提交于 2019-12-24 19:27:27

问题


My JS/jQuery knowledge is very basic so I'm asking for a bit of help here.

I'm trying to achieve something like a Pinterest effect with Thickbox.

What I'm assuming should happen is using JS or jQuery to monitor Thickbox actions (if #TB_window is present or not) and apply the following rules:

  • If Thickbox is opened -> set body style to overflow: hidden
  • Else Thickbox is closed -> set body style to overflow: auto

I'm using the integrated into WordPress Thickbox with the function - add_thickbox(); if it makes any difference.


回答1:


I'm unsure as to the construct of the page but the following code should fix it with a little tweaking

$(document).ready(function(){
    $('.element').click(function(){
        $('.body').css({'overflow':'hidden'});
    });
    $('.overlay, .close-button').click(function(){
        $('body').css({'overflow':'visible'});
    });
});

Just replace the following with the correct class names

.element - the class of the clickable link or image that opens the Thickbox
.overlay - the class of the semi-transparent overlay behind the Thickbox
.close-button - if needed, the class of the close button on the Thickbox



来源:https://stackoverflow.com/questions/20916086/if-thickbox-is-opened-set-body-noscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!