我正在使用fullpage.js生成全屏滑动网站。
我有四个插件生成的sections
四个导航点li
。第一li a
链接到first section
,第二li a
到second section
等
section1 li a
section2 li a
section3 li a
section4 li a
点击时section3
被删除。现在,我的部分少于导航点。
section1 li a
section2 li a
section4 li a
li a
由于某种原因,我需要第四个li a
仍然可以链接到section4
。
虽然我想restoreSection3()
在有人点击third li a
有人可以帮我吗?您可以检查jsfiddle示例以获得更好的理解。尝试删除section3
并使用右侧的导航。
一种可能的解决方案是,而不是通过切换幻灯片来删除幻灯片,而是将其display
设置height
为0来删除幻灯片,并隐藏其内容溢出。
像这样:
function removeSection3() {
// hide it by setting a height of 0, hiding overflow, and setting display to `block`
$("#f03").css({ display:"block", height:0, overflow:"hidden"});
silentScroll($('.fp-section.active').position().top);
}
function restoreSection3() {
// resetting the display to `table` will make the overflow visible again
$("#f03").css({ display:"table"});
silentScroll($('.fp-section.active').position().top);
}
您可以在此JSFiddle上看到该代码的演示:http : //jsfiddle.net/97tbk/616/
现在,当您单击第4个链接时,它会转到第4部分。在下面,当您单击第3个链接时,它也会转到第4部分。因此,让我们添加一个事件监听器来完成请求,该事件监听器将restoreSection3()
在li a
单击第三个事件时触发:
$("#fp-nav li:nth-child(3) a").on("click", function() {
// we restore section 3 by simulating clicking on the "Restore Section 3" button
$('button#first').click();
});
因此,最终代码如下所示:
function removeSection3() {
// hide it by setting a height of 0 and hiding the overflow
$("#f03").css({ display:"block", height:0, overflow:"hidden"});
// add an event listener, so when the third link is clicked, section 3 will be restored
$("#fp-nav li:nth-child(3) a").on("click", function() {
// we restore by simulating clicking on the "Restore Section 3" button
$('button#first').click();
});
silentScroll($('.fp-section.active').position().top);
}
function restoreSection3() {
// reset the display to table will make the overflow visible again
$("#f03").css({ display:"table"});
silentScroll($('.fp-section.active').position().top);
}
您可以看到它在其他JSFiddle上运行:http : //jsfiddle.net/97tbk/618/
现在,当您单击左侧的导航时,一切都按预期方式工作,尽管使用鼠标滚轮时似乎仍然有些时髦:由于第3部分将不启用,当第三个和第四个链接处于活动状态时,第4部分将显示。这种情况下的预期行为是什么?
不要试图质疑您这样做的原因,但是就可用性而言,最好删除第三部分和第三导航链接,因为如果用户看到4个导航链接而在浏览过程中只有3个部分,可能会感到困惑正在滚动。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句