我想通過CSS和可能的jQuery來實現這種效果。即創建一個隱藏的搜索欄,並在點擊標籤中的搜索圖標時向左滑動。但我不能。我確實設法做到了一些事情,但這很無聊。我希望轉換與W3school和其他許多網站的轉換類似。 這裏是我的代碼:我如何創建一個搜索欄,滑動到左側點擊標籤
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contac</a></li>
</ul>
<div id="search-enclose">
<form>
<div id="label-enclose">
<label></labe>
</div>
<div id="input-enclose">
<input type="text" placeholder="Enter Keyword">
</div>
</form>
</div>
</nav>
CSS:
nav {
position: relative;
}
ul {
position: absolute;
left: 25%;
list-stye: none;
z-index: 10;
}
li{
float: right;
}
#search-enclose {
width: 500px;
}
#label-enclose {
position: absolute;
top: 46px;
left: 30%;
height: 35px;
width: 60px;
line-height: 35px;
z-index: 20;
}
#label-enclose label {
display: block;
height: 35px;
width: 60px;
cursor: pointer;
}
#input-enclose {
position: absolute;
top: 46px;
width: 300px;
height: 35px;
z-index: 5;
overflow: hidden;
}
#input {
display: block;
position: absolute;
width: 270px;
height: 35px;
margin: 0;
border: none;
color: #fff;
font-size: 18px;
backface-visibility: none;
border-radius: 0;
transition: left 0;
}
#input-enclose input:focus {
outline: none;
}
#input-enclose .focus {
display: block;
}
#input-enclose .focus input {
left: 0;
transition: left 0.3s;
}
的JavaScript
var searchImage = document.getElementById('img');
var input = document.getElementById('input');
searchImage.addEventListener('click', function() {
if (classie.hasClass(input,'focus')) {
classie.removeClass(input,'focus')
}else {
classie.addClass(input, 'focus')
}
});
爲了什麼它的價值,這是幾乎是一個代碼,我在網上找到的副本,我的格式和CSS我很可怕,但我知道我想要什麼,有一個好的方向,我可以做到這一點。只是希望搜索欄顯示在導航列表項目頂部,點擊的方式很好, 我確實認爲CSS轉換可以實現,但它沒有。任何人都可以請我指出一個方向嗎?
你想搜索欄上點擊搜索圖標擴大?你覺得它什麼時候應該再次崩潰?我的意思是再次點擊圖標或其他方式? –
它應該最初隱藏,並顯示圖標被點擊的時間,但它顯示的方式是它會向左滑動併產生一些過渡效果。那就是在w3school。他們的搜索欄 – pedroyanky
您也可以從這些鏈接中獲得創意[鏈接1](http://tympanus.net/codrops/2013/06/26/expanding-search-bar-deconstructed/)和[鏈接2](http: //callmenick.com/post/expanding-search-bar-using-css-transitions)。 –