Tra*_*Coy 5 javascript jquery materialize material-design
使用Materializecss处理布局,在我的标题/导航中,我需要显示一个搜索图标,单击该图标时会展开搜索栏.
理想情况下,我希望它只是接管整个标题/ topnav,但任何扩展/到搜索栏的东西都很好.
除了提及基本代码之外,文档(http://materializecss.com/navbar.html)没有详细说明搜索栏:
<nav>
<div class="nav-wrapper">
<form>
<div class="input-field">
<input id="search" type="search" required>
<label for="search"><i class="material-icons">search</i></label>
<i class="material-icons">close</i>
</div>
</form>
</div>
</nav>
Run Code Online (Sandbox Code Playgroud)
怎么办呢?在Materialisecss/Material Design中我是否有一种标准方法可以做到这一点我不知道?
非常感谢
编辑:查看更新的 小提琴以获取扩展导航栏搜索的改进版本:)(在 Chrome 中没有不需要的行为)
好吧,因为他想要别的东西,正如我首先想到的,看看这个小提琴。需要一些基本的 jquery 函数:
$(document).ready(function() {
var trig = 1;
//animate searchbar width increase to +150%
$('#navbarsearch').click(function(e) {
if (trig == 1){
$('#expandtrigger').animate({
width: '+=150'
}, 400);
trig ++;
}
//handle other nav elements visibility here
$('.search-hide').addClass('hide');
});
// if user leaves the form the width will go back to original state
$("#navbarsearch").focusout(function() {
$('#expandtrigger').animate({
width: '-=150'
}, 400);
trig = trig - 1;
//handle other nav elements visibility here
$('.search-hide').removeClass('hide');
});
});
Run Code Online (Sandbox Code Playgroud)