我有一个示例代码,显示的搜索框中包含一些带css的动画,并使用jquery来切换它。
在我的代码中,我有一个额外的span元素,右边有一个加号图标。在扩展搜索和签约时,如何保持加号图标(仅)始终可见?
$("p").hide();
$('.opener').click(function() {
$(this).parent('.search').toggleClass('inactive').find('input').focus();
$(this).parent('.search').siblings('div.title').toggleClass('hideTitle')
});

.row {
border: 1px solid red;
}
.title {
font-size: 16px;
font-weight: bold;
position: absolute;
margin: 6px 0;
}
.input-group {
display: flex;
height: 36px;
width: 100%;
overflow: hidden;
padding: 0;
/*background-color: rgba(100, 100, 100, .1);*/
cursor: pointer;
/*border-radius: 2px;*/
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
/*box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);*/
}
.input-group:active,
.input-group:hover {
/*background-color: rgba(100, 100, 100, .1);*/
}
.input-group.centered {
margin: 0 auto;
}
.input-group .input-group-addon {
justify-content: center;
width: 36px;
background: transparent;
border: none;
display: flex;
text-align: center;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.input-group .input-group-addon i {
height: 24px;
width: 24px;
align-self: center;
color: #777;
}
.input-group input {
font-family: "Roboto", sans-serif;
background: transparent;
border: none;
box-shadow: none !important;
font-size: 16px;
padding: 0;
}
.inactive {
width: 36px;
border-radius: 18px;
background: transparent;
box-shadow: none;
}
.inactive .input-group-addon:not(:first-child) {
opacity: 0;
}
.row {
margin-top: 1em;
}
.hideTitle {
display: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300|Material+Icons' rel='stylesheet' type='text/css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="container">
<div class="row text-center">
<h1>Search Inputs</h1>
</div>
<div class="row">
<div class="title titleDiv">Title</div>
<div class="input-group search inactive pull-right">
<span class="input-group-addon opener">
<i class="material-icons">search</i>
</span>
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-addon opener">
<i class="material-icons">clear</i>
<span class="input-group-addon add"><i class="material-icons">add</i></span>
</span>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
用css怎么做?
.inactive .input-group-addon:not(:first-child) {
**opacity: 1;**
}
$("p").hide();
$('.opener').click(function() {
$(this).parent('.search').toggleClass('inactive').find('input').focus();
$(this).parent('.search').siblings('div.title').toggleClass('hideTitle')
});
&#13;
.row {
border: 1px solid red;
}
.title {
font-size: 16px;
font-weight: bold;
position: absolute;
margin: 6px 0;
}
.input-group {
display: flex;
height: 36px;
width: 100%;
overflow: hidden;
padding: 0;
/*background-color: rgba(100, 100, 100, .1);*/
cursor: pointer;
/*border-radius: 2px;*/
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
/*box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);*/
}
.input-group:active,
.input-group:hover {
/*background-color: rgba(100, 100, 100, .1);*/
}
.input-group.centered {
margin: 0 auto;
}
.input-group .input-group-addon {
justify-content: center;
width: 36px;
background: transparent;
border: none;
display: flex;
text-align: center;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.input-group .input-group-addon i {
height: 24px;
width: 24px;
align-self: center;
color: #777;
}
.input-group input {
font-family: "Roboto", sans-serif;
background: transparent;
border: none;
box-shadow: none !important;
font-size: 16px;
padding: 0;
}
.inactive {
width: 36px;
border-radius: 18px;
background: transparent;
box-shadow: none;
}
.inactive .input-group-addon:not(:first-child) {
**opacity: 1;**
}
.row {
margin-top: 1em;
}
.hideTitle {
display: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300|Material+Icons' rel='stylesheet' type='text/css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="container">
<div class="row text-center">
<h1>Search Inputs</h1>
</div>
<div class="row">
<div class="title titleDiv">Title</div>
<div class="input-group search inactive pull-right">
<span class="input-group-addon opener">
<i class="material-icons">search</i>
</span>
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-addon opener">
<i class="material-icons">clear</i>
<span class="input-group-addon add"><i class="material-icons">add</i></span>
</span>
</div>
</div>
</div>
&#13;