我有一个自动滚动功能,有一个静态箭头可以让用户滚动到页面的下一部分。当用户到达“联系”部分(最后一页)时,我希望箭头隐藏,因为没有其他页面可以向下滚动。当底部页面部分到达时,jquery隐藏带锚文本的div
更新 -
目前最后一页上的导航箭头自败,但它也自败在约和简介部分太..我怎样才能解决
jQuery的 - 更新V3
$(function() {
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');
event.preventDefault();
});
});
function nextSection()
{
var scrollPos = $(document).scrollTop();
$('#section-navigator a').each(function() {
var currLink = $(this);
var refElement = $(currLink.attr("href"));
if (refElement.position().top > scrollPos) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');
event.preventDefault();
location.hash = "";
location.hash = currLink.attr("href");
if ($($anchor.attr('href')).attr('id') == "contact") {
$("div.page-scroll").hide();
}
return false;
}
});
}
HTML
<div class="page-scroll">
<img class="arrow-down page-scroll-btn" src="img/arrow_dark.png" onclick="nextSection()" />
</div>
谢谢!
做的:
获取你的jQuery的顶部,要手动在HTML你的下一个部分的功能结合,改变以摆脱的jQuery的onclick绑定功能的你在控制台上打印$($ anchor.attr('href'))的值来检查执行是否进入'if'块?如果是的话$($ anchor.attr('href'))的值是多少?去做。因为很可能,您的执行不会进入'if'块并执行'else'块。在else块中添加一条语句,如console.log(“else block”),以查看它是否进入if块或else块。 –
你应该在'if($($ anchor.attr('href'))=='contact')'' – Poonam
mm'这样的括号里使用'if'的条件,如果我把它放在奇怪的位置 - if($($ anchor.attr ('href'))==“contact”){ $(“a.page-scroll”)。hide(); } } 它仍然无法正常工作......我应该把它放在下一个函数或第一个函数 – user1673498