我尝试复制类似于此website的导航栏。因此,当用户打开网站时,有一个非粘性导航栏,用户向下滚动一点非粘性导航栏,并用粘性导航栏取代。如何用materialize css实现这样的东西?到目前为止,我只做了非粘性导航栏部分
<nav class="nav-extended">
<div class="nav-wrapper">
<a href="#" class="brand-logo"><img src="viva.png" alt="" id="logo"></a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>
<form>
<div class="input-field">
<input id="search" type="search" required>
<label class="label-icon" for="search"><i class="material-icons"></i></label>
<i class="material-icons">close</i>
</div>
</form>
</li>
<li><a href="#">Register</a></li>
<li>|</li>
<li><a href="#">Login</a></li>
</ul>
</div>
<hr>
<div class="nav-content">
<ul class="tabs tabs-transparent">
<li class="tab"><a href="#">Test 1</a></li>
<li class="tab"><a href="#">Test 2</a></li>
<li class="tab"><a href="#">Test 3</a></li>
</ul>
</div>
</nav>
答案 0 :(得分:0)
试试这个:
HTML
<div class="header">Header Example</div>
<div class="content">
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur.
</p>
</div>
CSS
body {
margin:0;
padding:0;
font-family: Arial, sans-serif;
}
header {
position: relative;
width: 100%;
height: 80px;
line-height: 80px;
background: #CCCCCC;
color: #333333;
padding-left: 25px;
}
header.fixed {
position:fixed;
top:-80px;
left: 0;
right: 0;
z-index:8888;
transition:0.3s top cubic-bezier(.3,.73,.3,.74);
}
body.on-scroll header.fixed {
top:0;
}
.content {
padding: 25px;
background: #fff;
line-height: 1.4;
color: #333;
min-height: 2700px; /* You can remove this,is just for demo purpose */
}
jquery的:
(function($){
$(document).ready(function() {
var $header = $(".header"),
$clone = $header.before($header.clone().addClass("fixed"));
$(window).on("scroll", function() {
var fromTop = $(window).scrollTop();
$("body").toggleClass("on-scroll", (fromTop > 200));
});
});
})(jQuery);
这是一个jsfiddle示例。