Body 关闭按钮

Body Close button

我制作了一个悬浮在屏幕中间的表格

为此我设计了一个关闭按钮

但我想在屏幕上的任意位置用鼠标单击关闭表单

我的代码

  $(".offer-close").click(function () {
         $(".div-fix").fadeOut(500);
     });
<div class="div-fix">
<div class="offer-shop">

    <div class="cur-package">
        <div class="offer-close"><i class="fa fa-times"></i></div>
        <h6>Service</h6>

        <div class="pack-b">

            <div class="pack-price">6500 <div>
            <br>

            <div class="pack-shop"><a href="#" target="blank">Buy</a></div>
        </div>
        <div class="pack-c">any ...</div>
    </div>
</div>
</div>

例如表单反馈网站:http://cssdeck.com/

添加以下脚本即可解决您的问题。

$(document).mouseup(function (e)
{
    var container = $(".div-fix");

    if (!container.is(e.target) // if the target of the click isn't the container...
        && container.has(e.target).length === 0) // ... nor a descendant of the container
    {
        container.hide();
    }
});

jsFiddle Demo