身体关闭按钮

Body Close button

本文关键字:关闭按钮      更新时间:2023-09-26

我制作了一个浮动在屏幕中间的表单

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

但我想在屏幕上的任何地方点击鼠标关闭

我的代码

  $(".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演示