Javascript 使用fullPage onLeave时定位点不起作用
我的菜单和定位点一切正常,但添加以下代码后链接停止工作:Javascript 使用fullPage onLeave时定位点不起作用,javascript,jquery,fullpage.js,Javascript,Jquery,Fullpage.js,我的菜单和定位点一切正常,但添加以下代码后链接停止工作: $('#fullpage').fullpage({ onLeave: function(index, nextIndex, direction){ var leavingSection = $(this); //after leaving section 2 if(index == 1 && direction =='down'){ $('h
$('#fullpage').fullpage({
onLeave: function(index, nextIndex, direction){
var leavingSection = $(this);
//after leaving section 2
if(index == 1 && direction =='down'){
$('header').addClass('active');
}
else if(index == 2 && direction == 'up'){
$('header').removeClass('active');
}
}
});
我的意图是隐藏我的标题,只在第二节之后显示它,这种情况发生了,但是锚定点不再起作用
我的标题html
<header>
<ul id="myMenu">
<li data-menuanchor="topo" class="active"><a href="#topo"><img src="img/dcb-white.svg"></a></li>
<li data-menuanchor="contato"><a href="#contato">Contato</a></li>
<li data-menuanchor="sobre"><a href="#sobre">Sobre Mim</a></li>
<li data-menuanchor="historico"><a href="#historico">Histórico</a></li>
<li data-menuanchor="portfolio"><a href="#portfolio">Portfolio</a></li>
<li data-menuanchor="topo" class="active"><a href="#topo">Topo</a></li>
</ul>
</header>
在中,我可以使用css实现我想要的效果,但我仍然不明白为什么onLeave代码不起作用:
好吧,基本上你没有告诉fullpage.js你想使用锚 您必须在初始化中使用
锚定
选项(您没有使用),或者在每个部分中使用数据锚定
属性。(看起来你两个都没有用)
阅读更多关于它的信息
锚定:(默认值[])定义要在每个节的URL上显示的锚定链接(#示例)。锚定值应该是唯一的。锚点在阵列中的位置将定义锚点应用于哪些截面。(第二部分的第二个位置,依此类推)。也可以通过浏览器使用锚向前和向后导航。此选项还允许用户为特定的部分或幻灯片添加书签。小心!锚点不能与站点上的任何ID元素(或IE的名称元素)具有相同的值。现在可以通过使用属性数据锚在HTML结构中直接定义锚,如下所述
header{
position:fixed;
height: auto;
display:block;
width: 100%;
background: #000;
z-index:9;
text-align:center;
color: #fff;
top:0px;
visibility: hidden;
opacity: 0;
-webkit-transition: all 0.8s;
-moz-transition: all 0.8s;
transition: all 0.8s;
}
header.active {
visibility: visible;
opacity: 1;
-webkit-transition: all 0.8s;
-moz-transition: all 0.8s;
transition: all 0.8s;
}