簡體   English   中英

單擊外部背景div時如何退出彈出式聯系表單?

[英]How do I make a popup contact form exit when clicking the external background div?

我有一個聯系表單,該表單以黑色背景div和內部打開,另一個div帶有表單本身。

我將聯系人表單設置為X按鈕以退出,現在我希望在單擊黑色背景時退出該聯系人。

在此處輸入圖片說明

我該怎么做呢?

這是我的HTML:

<div class="contact_form">

    <div class="form_container">

        <div class="the-x-container">
            <span class="the-x">X</span>
        </div>

        <h1>Contact Us</h1>

        <h2><span class="text-orange">Improve</span> Business Performance</h2>

        <div class="line"></div>

        <div class="form_content">
            <div> <span> Name:    </span> <input type="text" id="fullname"> </div>
            <div> <span> E-mail:  </span> <input type="text" id="email">    </div>
            <div> <span> Message: </span> <input type="text" id="text">     </div>
            <div id="sendBtn"> Submit </div>
        </div>

        <div id="aboutSuccess">
            Thank you for reaching out! <br>Our team will be in contact with you shortly.
            <!--iframe id="pixel-thing" src="http://www.example.com/thePixel.html" width="1" height="1" style="display: none;" border="0"></iframe-->
        </div>      

        <div id="aboutUnsuccess">
            Invalid Email address. <br><span id="tryAgain">Click here</span> to try again.
        </div>

    </div>

</div> 

這是我的CSS:

/********************************************* Contact Form ******************************************************/

.contact{
    cursor: pointer;
    color: #fff;
}

html.stop-scrolling {
    /*width: 100%;
    position: fixed;*/
    position: fixed;
    width: 100%;
    top:0;
    left: 0;
    height: 100%;
    overflow-y: scroll !important;
    z-index: 10;
}

.contact_form{
    display    : none;
    width      : 100%; 
    height     : 100%;
    background : rgba(0, 0, 0, 0.7);;
    position   : absolute;
    top        : 0;
    left       : 0;
    z-index    : 800;
}

.contact_form .form_container{
    background-image: url('images/popup.png');
    background-size: 100%;
    background-repeat: no-repeat;
    display: block;
    width: 45.8em;
    height: 50em;
    z-index: 850;
    position: fixed;
    top: 22%;
    left: 34%;
    padding-left: 10px;
    margin: auto;
}

.contact_form .the-x-container{
    width: 32em;
    padding-top: 5.4em;

}

.contact_form .the-x{
    color: #f46406;
    font-weight: bold;
    float: right;
    font-size: 1.3em;
    cursor: pointer;
}

.contact_form h1{
    font-family: 'FSR';
    text-align: center;
    color: #fff;
    font-size: 4em;
    padding-top: 1.7em;
    width: 8.5em;
    height: 0.9em;
}

.contact_form h2{
    font-family: 'Bauhaus93R';
    text-align: center;
    color: #fff;
    font-size: 1.7em;
    width: 21.1em;
} 

.contact_form .line{
    height: 1em;
    width: 30em;
    margin: 0 0 0 3.9em;
    background-image: url('images/popup_stroke.png');
    background-size: 100%;
    background-repeat: no-repeat;
}

.contact_form .form_content {
    width: 34em;
    margin: 1em auto;
}

.contact_form .form_content div{
    font-size: 1.5em;
}

.contact_form .form_content span{
    color: #f46406;
}

.contact_form input{
    border-width: 0px 0px 1px 0px; 
    border-style: solid;
    border-color: #fff;
    background-color: transparent;  
    outline: 0;
}

.contact_form #fullname {
    font-size: 1.1em;
}

.contact_form #email {
    font-size: 1.1em;
}

.contact_form #text {
    font-size: 1.1em;
}

.contact_form #sendBtn{
    cursor: pointer;
    color: #f46406;
    text-decoration: underline;
    text-align: center;
    width: 15em;
    margin-top: 1em;
}

.contact_form #aboutSuccess{
    display: none;
}

.contact_form #aboutUnsuccess{
    display: none;
}

這是我目前的JS:

$('.the-x').click(function(){
    $('.contact_form').fadeOut("slow");
    $('html').removeClass("stop-scrolling")
})

我嘗試使用:

$('.contact_form').click(function(){
    $('.contact_form').fadeOut("slow");
    $('html').removeClass("stop-scrolling")
})

但是只要單擊表單字段=表單就會隱藏。

$('.contact_form').click(function(e){
    //check whether the target of the click has form_container as a parent
    if (!$(e.target).closest('.form_container').length) {
        $('.contact_form').fadeOut("slow");
        $('html').removeClass("stop-scrolling")
    }
})

http://codepen.io/jlowcs/pen/xbQZZo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM