在输入之外单击,返回false?

时间:2018-08-21 18:37:43

标签: css

我用CSS创建了简单的动画。源代码在这里: https://drive.google.com/open?id=1MWOHpjTeqr_CBQaCvE4ccoY8nD8kjGFo 但是我有一个问题,当您单击“搜索”并且所有动画将结束,然后在输入之外的某个位置单击时,输入将再次变为圆形。在输入内容之外单击时如何取消对Circle的支持?

body{
    margin: 0;
    padding: 0;
    background-color: #999999;
}
input{
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    position: absolute;
    border: none;
    border-radius: 50%;
    width: 200px;
    height: 200px;
    background-color: #404040;
    text-align: center;
    color: #fff;
    font-size: 50px;
    font-family: 'Catamaran';
    outline: none;
    
}
input:hover{
    background-color: #ff8533;
    transition: 0.8s;
    cursor: pointer;
}
input:focus{
    animation: test 1s;
    animation-fill-mode: forwards;
    text-align: left;
}

::placeholder{
    color: #fff;
    font-weight: 600;
    letter-spacing: 1px;
}
@keyframes test{
    100%{width: 450px; border-radius: 30px; height: 100px; background-color: #595959; border: 1px solid #404040; cursor: auto; padding: 0px 20px;}
}
@keyframes test2{
    100%{ 
    border-radius: 50%;
    width: 200px;
    height: 200px;
    background-color: #404040;
    cursor: pointer;
    padding: 0px;
}
}
<html>
    <head>
        <title>Web Developing</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet">
    </head>
    <body>
            <input type="text" placeholder="Search">
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

在点击处理程序中,您可以更改输入类别,然后将该类别添加到悬停/焦点样式:

  

input:focus,input.classaddedonclick {

答案 1 :(得分:0)

您最好的选择是,在初次使用JavaScript时将一个类添加到您的输入中。虽然,您也可以通过将动画转换为过渡并赋予其确实长的反向过渡延迟来做到这一点。请注意,text-align无法转换,因此占位符将需要进行其他调整才能正常工作。

body{
    margin: 0;
    padding: 0;
    background-color: #999999;
}
input{
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    position: absolute;
    border-width: 0px;
    border-radius: 50%;
    width: 200px;
    height: 200px;
    background-color: #404040;
    text-align: center;
    color: #fff;
    font-size: 50px;
    font-family: 'Catamaran';
    outline: none;
    transition: all 1s 999999s;
    
}
input:hover{
    background-color: #ff8533;
    transition: 0.8s;
    cursor: pointer;
}
input:focus{
    transition: all 1s;
    text-align: left;
    width: 450px;
    border-radius: 30px; 
    height: 100px; 
    background-color: #595959; 
    border-width: 1px;
    border-style: solid;
    border-color: #404040; 
    cursor: auto; 
    padding: 0px 20px;
}

::placeholder{
    color: #fff;
    font-weight: 600;
    letter-spacing: 1px;
}
@keyframes test{
    100%{width: 450px; border-radius: 30px; height: 100px; background-color: #595959; border: 1px solid #404040; cursor: auto; padding: 0px 20px;}
}
@keyframes test2{
    100%{ 
    border-radius: 50%;
    width: 200px;
    height: 200px;
    background-color: #404040;
    cursor: pointer;
    padding: 0px;
}
}
<html>
    <head>
        <title>Web Developing</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet">
    </head>
    <body>
            <input type="text" placeholder="Search">
    </body>
</html>