Body Close button

I've made a form floating in the middle of the screen

And for that I designed a button to close

But I want be anywhere on the screen with the mouse clicked closed form

my code

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

For example, form feedback website : http://cssdeck.com/

Answers 1

  • Adding below script will solve your problem.

    $(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


Related Articles