Pra*_*abu 2 html javascript css jquery fullpage.js
我正在fullpage.js中构建一个页面.在第一张幻灯片上是一个消耗视口高度90%的图像.另外10%是图像下方的导航栏.下图显示了它.

当我滚动到下一张幻灯片时,我希望导航栏成为其余幻灯片的固定标题.
一旦它的offset().top值为0,我尝试$(window).top()使用jQuery来修复元素.这不适合我.
$(window).scroll(function () {
var nav = $('#nav');
var eTop = nav.offset().top;
if ((eTop - $(window).scrollTop()) == 0) {
nav.addClass('fixed');
}
else {
nav.removeClass('fixed');
}
});
Run Code Online (Sandbox Code Playgroud)
这是可能的,我该如何实现?
如果您使用的是默认选项css3:true,那么这将解决问题:
$('#fullpage').fullpage({
sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
onLeave: function(index, nextIndex, direction){
//leaving 1st section
if(index == 1){
$('.header').addClass('fixed');
}
//back to the 1st section
if(nextIndex == 1){
$('.header').removeClass('fixed');
}
}
});
Run Code Online (Sandbox Code Playgroud)
你需要这个CSS作为标题元素:
.header{
-webkit-transition: all 0.7s ease;
-moz-transition: all 0.7s ease;
-o-transition: all 0.7s ease;
transition: all 0.7s ease;
position:absolute;
top:100%;
margin-top: -100px;
left:0;
background:#000;
width:100%;
color: #fff;
height: 100px;
z-index:999;
}
.header.fixed{
bottom:auto;
top:0;
margin-top: 0;
}
Run Code Online (Sandbox Code Playgroud)
你当然可以改变高度等等.
考虑到我已经将固定元素放在插件的包装器之外.这样我就可以避免translate3d插件使用的属性出现问题:
<div class="header">Header</div>
<div id="fullpage">
<div class="section">...</div>
<div class="section">...</div>
...
</div>
Run Code Online (Sandbox Code Playgroud)
如果您正在使用scrollBar:true,请使用以下CSS而不是前一个CSS:
.section {
text-align:center;
}
.header{
-webkit-transition: all 0.7s cubic-bezier(0.895, 0.030, 0.685, 0.220);
-moz-transition: all 0.7s cubic-bezier(0.895, 0.030, 0.685, 0.220);
-o-transition: all 0.7s cubic-bezier(0.895, 0.030, 0.685, 0.220);
transition: all 0.7s cubic-bezier(0.895, 0.030, 0.685, 0.220);
position:fixed;
top:100%;
margin-top: -100px;
left:0;
background:#000;
width:100%;
color: #fff;
height: 100px;
z-index:999;
}
.header.fixed{
bottom:auto;
top:0;
margin-top: 0;
position:fixed;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7086 次 |
| 最近记录: |