简体   繁体   English

如何使用jquery创建覆盖式联系表单

[英]How do I use jquery to create an overlay contact form

I wrote some jquery that creates an overlay box with log in information. 我写了一些jquery,用登录信息创建一个覆盖框。 When the user presses 'Log In' on the navigation, it works great. 当用户在导航上按“登录”时,效果很好。

Fiddle 小提琴

I did have a separate page for a contact form. 我确实有联系页面的单独页面。 But I've decided I'd rather just have an overlay contact form, just like the log in. However, the second object doesn't display like the log in form does. 但是我已经决定,我宁愿像登录一样拥有一个重叠联系人表单。但是,第二个对象却不像登录表​​单那样显示。

I must be doing something wrong but I'm not sure what it is 我一定在做错事,但是我不确定那是什么

HTML 的HTML

<!--POP UP FORM-->
<div id="login-box" class="login-popup">
    <a href="#" class="close"><img src="images/mini_green_x2.png" class="btn_close" title="Close Window" alt="Close" /></a>
    <form action="https://www.theiracenter.com/customerLoginAction.gsx" method="post">
        <label for="username">Username:</label>
        <br />
        <input class="topLogin" type="text" name="login" width="125px" />
        <br />
        <label for="password">Password:</label>
        <br />
        <input class="topLogin" id="passwordText" type="password" name="password" width="125px" />
        <input type="hidden" name="pd" value="C05" />
        <br />
        <input type="submit" id="loginSubmit" value="Submit" />
    </form>
</div>

<div id="contact-box" class="login-popup">
    <a href="#" class="close"><img src="images/mini_green_x2.png" class="btn_close" title="Close Window" alt="Close" /></a>
    Contact Us!
</div>

<div class="d5-d10 m1" id="navHolder">
    <ul id="mainNavigation">
        <li><a href="#login-box" class="login-window">Log In</a></li>
        <li><a href="#contact-Box" class="login-window">Contact</a></li>
        <li><a href="investment.html">Investment</a></li>
        <li><a href="faq.html">FAQ</a></li>
    </ul>
</div>

JQUERY JQUERY

<script type="text/javascript">
$(document).ready(function () {
    $('a.login-window').click(function () {

        // Getting the variable's value from a link
        var loginBox = $(this).attr('href');

        //Fade in the Popup and add close button
        $(loginBox).fadeIn(300);

        //Set the center alignment padding + border
        var popMargTop = ($(loginBox).height() + 24) / 2;
        var popMargLeft = ($(loginBox).width() + 24) / 2;

        $(loginBox).css({
            'margin-top': -popMargTop,
            'margin-left': -popMargLeft
        });

        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);

        return false;
    });

    // When clicking on the button close or the mask layer the popup closed
    $('body').on('click', 'a.close, #mask', function () {
        $('#mask , .login-popup').fadeOut(300, function () {
            $('#mask').remove();
        });
        return false;
    });
});
</script>

And CSS 和CSS

/*LOG IN POP UP*/
/* Mask for background, by default is not display */
#login-box label{
    font-family:'Droid Sans', sans-serif;
    color:#6EBE44
}

#login-box img{
    float:right;
}

#mask {
    display: none;
    background: #000;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    width: 100%;
    height: 100%;
    opacity: 0.8;
    z-index: 999;
}

.login-popup {
    display: none;
    background: #666666;
    padding: 10px;
    border: 2px solid #ddd;
    float: left;
    font-size: 1.2em;
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 99999;
    box-shadow: 0px 0px 20px #999;
    /* CSS3 */
        -moz-box-shadow: 0px 0px 20px #999;
    /* Firefox */
        -webkit-box-shadow: 0px 0px 20px #999;
    /* Safari, Chrome */
    border-radius: 3px 3px 3px 3px;
    -moz-border-radius: 3px;
    /* Firefox */
        -webkit-border-radius: 3px;
    /* Safari, Chrome */;
}

img.btn_close {
    Position the close button
    float: right;
    margin: -28px -28px 0 0;
}

fieldset {
    border: none;
}

form.signin .textbox label {
    display: block;
    padding-bottom: 7px;
}

form.signin .textbox span {
    display: block;
}

form.signin p, form.signin span {
    color: #999;
    font-size: 11px;
    line-height: 18px;
}

form.signin .textbox input {
    background: #666666;
    border-bottom: 1px solid #333;
    border-left: 1px solid #000;
    border-right: 1px solid #333;
    border-top: 1px solid #000;
    color: #fff;
    border-radius: 3px 3px 3px 3px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    font: 13px Arial, Helvetica, sans-serif;
    padding: 6px 6px 4px;
    width: 200px;
}

form.signin input:-moz-placeholder {
    color: #bbb;
    text-shadow: 0 0 2px #000;
}

form.signin input::-webkit-input-placeholder {
    color: #bbb;
    text-shadow: 0 0 2px #000;
}

.button {
    background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
    background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
    background: -o-linear-gradient(top, #f3f3f3, #dddddd);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
    border-color: #000;
    border-width: 1px;
    border-radius: 4px 4px 4px 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;
    color: #333;
    cursor: pointer;
    display: inline-block;
    padding: 6px 6px 4px;
    margin-top: 10px;
    font: 12px;
    width: 214px;
}

.button:hover {
    background: #ddd;
}

我认为这只是一个案例错误:您有id="contact-box"href="#contact-Box"

just a small mistake 只是一个小错误

type mistake :p 输入错误:p

change this 改变这个

<div id="contact-box" class="login-popup">

into 进入

<div id="contact-Box" class="login-popup">

The problem is in your href of anchor tag, href of contact does not match with id you provided to overlay div. 问题出在锚标签的href中,联系人的href与您提供给覆盖div的ID不匹配。

Here is working fiddle http://jsfiddle.net/L784A/1/ 这是工作提琴http://jsfiddle.net/L784A/1/

     <li><a href="#contact-box" class="login-window">Contact</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM