classList.toggle切换样式,但样式本身未应用

时间:2019-11-23 16:21:23

标签: javascript css class toggle

我是不熟悉classList.toggle的新手,但是我已经在其他项目中使用它了,没有问题,我要做的就是在弹出的窗口中单击X时运行css动画,但是没有应用风格 有人知道这是为什么吗?我完全迷住了,我的JS没问题,所以这是我不知道的CSS问题吗?如果有人可以帮助,将不胜感激。

CSS:

   @import url('https://fonts.googleapis.com/css?family=Poppins&display=swap');

*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}

body{
    background: #222;
    font-family: 'Poppins', sans-serif;
}

#popUp-wrapper{
    position: relative;
    top:-400px;
    width:500px;
    margin:0 auto;
    text-align: center;
}

#popUp-wrapper .content_container{
    background-color: #6ba8a9;
    padding: 30px;
    position: absolute;
    width: auto;
}

h1{
    font-size:30px;
    margin:18px 0;
    letter-spacing:1px;
    line-height:50px;
    color: #202225;
    padding-bottom:1px
}

.line{
    width:280px;
    height:2px;
    background: white;
    margin-left:16%;
}

p{
    color: #202225;
    padding:18px 6px;
}

/*Input Styles*/

#popUp-wrapper input{
    font-family: 'Poppins', sans-serif;
    padding:10px;
    border:0;
    outline: none;
    border-radius:10px 10px 10px 10px;
    border:2px solid white;
    background-color: #222;
    color:#6ba8a9
}

::placeholder{
    color:#6ba8a9;
    font-size:15px;
}

#popUp-wrapper input:focus{
    color:#6ba8a9;
}

/*Button Styles*/
button{
    font-family: 'Poppins', sans-serif;
    padding:10px;
    border:2px solid white;
    border-radius: 0 10px 10px 0;
    background-color:#222;
    color: #6ba8a9;
    margin-left:-9px;
    cursor: pointer;
}

/*X Window styles*/
#close_cross{
    position: absolute;
    top:10px;
    left:10px;
    background:white;
    color:#222;
    font-weight: bold;
    width:20px;
    height:20px;
    text-align: center;
    border-radius:11px;
    cursor: pointer;
    outline: none;
}

/*Animation Styles*/
#popUp-wrapper{
    transform-origin: 10px 10px;
    animation: drop_down 0.5s ease forwards;
}


/*Keyframes*/
@keyframes drop_down{
    0%{opacity:0}
    70%{transform: translateY(800px)}
    100%{transform: translateY(720px)}
}

@keyframes swing{
  0%{ transform: translateY(720px) rotateZ(0deg)}
  40%{transform: translateY(720px) rotateZ(90deg)}
  70%{transform: translateY(720px) rotateZ(70deg)}
  100%{transform: translateY(720px) rotateZ(75deg)}
}

@keyframes fall{
  0%{transform: translateY(720px) rotateZ(75deg)}
  40%{transform: translateY(1000px) rotateZ(75deg)}
  100%{transform: translateY(3000px) rotateZ(75deg)}
}

/*Toogled Classes*/
.swing #popUp-wrapper{
    animation: swing 2s ease forwards,
    fall 2s 2s ease-in forwards;
}

JS:

 //ID's & Classes
const closeX = document.getElementById("close_cross");
const popUp = document.getElementById("popUp-wrapper");

const xClicked = () =>{
    const popUp = document.getElementById("popUp-wrapper").classList.toggle("swing");
}

0 个答案:

没有答案
相关问题