Close a div by clicking outside

前端 未结 7 953
感情败类
感情败类 2020-11-27 06:05

I want to hide a div by clicking on the close link in it, or by clicking anywhere outside that div.

I am trying following code, it opens and close t

相关标签:
7条回答
  • 2020-11-27 07:01

    Add a transparent background taking up the whole window size, just before your popup div

    .transparent-back{
        position: fixed;
        top: 0px;
        left:0px;
        width: 100%;
        height: 100%;
        background-color: rgba(255,255,255,0.5);
    }
    

    Then on its click, dismiss the popup.

    $(".transparent-back").on('click',function(){
        $('popup').fadeOut(300);
    });
    
    0 讨论(0)
提交回复
热议问题