如何防止CSS弹出冲突的index.html CSS?

时间:2016-04-14 01:54:06

标签: javascript jquery css

我尝试使用codepen用户Kyle Lavery sign up modal中的表单作为弹出窗口。我在index.html中使用overflow: hidden。我的问题是,contact.html已将body应用于与index.html冲突的*, :before, :after。应用于body的样式也是一个问题,但到目前为止,我无法分辨。我尝试在整个表单和它的父div之间放置一个div并将$(".close, .nope").on('click', function () { $('.modal').addClass('hidden'); $('.open').addClass('active'); }) $(".open").on('click', function () { $(this).removeClass('active'); $('.modal').removeClass('hidden'); })的样式应用到它,但这会导致动画略微抖动。关于如何在保持动画流畅的同时应用此CSS的任何建议?我的下一个想法是使用jQuery仅在弹出窗口打开时应用此CSS。查看整个片段以正确查看动画。



*, :before, :after {
  box-sizing: border-box;
  margin: 0;
  -webkit-transition: 0.4s;
          transition: 0.4s;
}

body {
  overflow: hidden;
}

.popup {
  color: #FFF;
  font-family: Roboto;
}

.modal {
  height: 450px;
  width: 650px;
  margin: auto;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  -webkit-transition: .4s, box-shadow .3s .4s;
          transition: .4s, box-shadow .3s .4s;
}
.modal.hidden {
  box-shadow: none;
  -webkit-transition: .4s, box-shadow 0s;
          transition: .4s, box-shadow 0s;
  opacity: 0;
  filter: alpha(opacity=0);
  visibility: hidden;
}
.modal.hidden .form {
  top: 100%;
}
.modal.hidden .invite {
  top: -100%;
}
.modal.hidden .invite .close {
  height: 0;
  width: 0;
  top: 0;
  right: 0;
}

.form, .invite {
  background: rgba(71, 71, 71, 0.8);
  width: 50%;
  height: 100%;
  padding: 25px;
  position: absolute;
  top: 0;
  left: 0;
}

input {
  background: rgba(255, 255, 255, 0.15);
  width: 100%;
  padding: 8px;
  margin: 15px 0;
  border: none;
  border-radius: 3px;
  outline: none;
  color: #FFF;
  font-size: 20px;
}
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0px 500px #7a7a7a inset;
  -webkit-text-fill-color: #FFF;
}

label {
  font: 500 14px Roboto;
  color: #ffb66e;
}

button {
  background: -webkit-linear-gradient(135deg, #f04527, #ffb66e);
  background: linear-gradient(-45deg, #f04527, #ffb66e);
  padding: 10px 20px;
  border: none;
  border-radius: 21px;
  outline: none;
  overflow: hidden;
  position: absolute;
  bottom: 30px;
  left: 50%;
  color: #FFF;
  font-size: 18px;
  cursor: pointer;
  -webkit-transform: translateX(-50%);
      -ms-transform: translateX(-50%);
          transform: translateX(-50%);
}
button:hover:before {
  left: 110%;
  -webkit-transition: .3s;
          transition: .3s;
}
button:before {
  content: '';
  background: rgba(255, 255, 255, 0.3);
  height: 100%;
  width: 65px;
  position: absolute;
  top: 0;
  left: -100%;
  -webkit-transform: skew(-45deg);
      -ms-transform: skew(-45deg);
          transform: skew(-45deg);
  -webkit-transition: 0s;
          transition: 0s;
}

.invite {
  background: -webkit-linear-gradient(135deg, #f04527, #ffb66e);
  background: linear-gradient(-45deg, #f04527, #ffb66e);
  left: 50%;
}

h2 {
  font: 30px Roboto;
  text-transform: uppercase;
}

.close {
  background: #474747;
  height: 30px;
  width: 30px;
  border: 3px solid #FFF;
  border-radius: 50%;
  position: absolute;
  top: -15px;
  right: -15px;
  cursor: pointer;
  -webkit-transition: .4s .3s;
          transition: .4s .3s;
}
.close:before, .close:after {
  content: '';
  background: #FFF;
  height: 80%;
  width: 3px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%) rotate(-45deg);
      -ms-transform: translate(-50%, -50%) rotate(-45deg);
          transform: translate(-50%, -50%) rotate(-45deg);
}
.close:after {
  -webkit-transform: translate(-50%, -50%) rotate(45deg);
      -ms-transform: translate(-50%, -50%) rotate(45deg);
          transform: translate(-50%, -50%) rotate(45deg);
}

.open {
  color: black;
  height: 45px;
  width: 150px;
  padding: 10px 20px;
  margin: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  filter: alpha(opacity=0);
  visibility: hidden;
}
.open.active {
  opacity: 1;
  filter: alpha(opacity=100);
  visibility: visible;
}

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Daily UI #001 - Sign Up Modal</title>


    <link href="http://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" type="text/css">

    <link rel="stylesheet" href="css/contact.css">

</head>

<body>
    <div class="popup">
        <a class="open active" title="open modal" href="#">Open Modal</a>
        <div class="modal hidden">
            <div class="form">
                <form>
                    <label for="first-name" required="required">First Name</label>
                    <input id="first-name" type="text" />
                    <label for="last-name" required="required">Last Name</label>
                    <input id="last-name" type="text" />
                    <label for="email" required="required">Email Address</label>
                    <input id="email" type="email" />
                    <label for="message">Message</label>
                    <input id="message" type="text" />
                    <button type="button">Send</button>
                </form>
            </div>
            <div class="invite">
                <h2>Thank you for your interest. I look forward to speaking with you soon.</h2>
                <div title="close" class="close"></div>
            </div>
        </div>

    </div>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

    <script src="js/contact.js"></script>




</body>

</html>
&#13;
var target = $(this).next(recipient);
if (target.length == 0) { // reached the end of this div
    target = $(this).closest('ul').next(recipient);
}
target.toggleClass("open");
&#13;
&#13;
&#13;

0 个答案:

没有答案