HTML
<div id="searchDiv">
<input type="search" placeholder=" 搜索" id="search">
<span id="serachIcon"><i class="fa fa-search"></i></span>
</div>
CSS
/*搜索*/
#searchDiv{
float: left;
margin-left: 50px;
width: 240px;
height: 40px;
margin-top: 5px;
margin-bottom: 5px;
position: relative;
}
#search{
padding-left: 20px;
width: 0px;
transition: all .3s linear ;
-moz-transition: all .3s linear;
-o-transition: all .3s linear;
-webkit-transition: all .3s linear;
opacity: 0; //完全透明
visibility: hidden; //不可见
display:inline-block;
height: 40px;
border-radius: 30px;
border-width: 0px;
background-color: #EEEEEE;
}
#search:focus{
outline:none;//设置获取焦点时外边框不亮
}
#searchDiv i{
display: inline-block;
font-size: 18px;
color:#B6B6B6;
width: 30px;
height: 30px;
line-height: 30px;
margin: 5px;
text-align: center;
border-radius: 50%;
background-color: #969696;
position: absolute;
top: 0px;
}
JS
//搜索框
document.getElementById("searchDiv").addEventListener("mouseover",function(){
document.getElementById('search').style.width='200px';
document.getElementById('search').style.opacity='1';
document.getElementById('search').style.visibility='visible';
});
document.getElementById("searchDiv").addEventListener("mouseout",function(){
document.getElementById('search').style.width='0px';
document.getElementById('search').style.opacity='0';
document.getElementById('search').style.visibility='hidden';
});