我已阅读有关此主题的所有问题和答案。这应该是一项简单的任务,但我无法让它发挥作用。
Waypoint的JQuery版本在一个页面网站上的顶级菜单项上运行良好。我想在单击这些菜单项时禁用它,然后将其还原。我还没有进入恢复部分。当我调用disable函数时,我得到一个" TypeError:e.disable而不是函数"。注释行显示了我尝试包含disable()函数的所有方法:
var waypoints = $('section.waypoint').waypoint({
handler:function(){
var hash = '#'+this.element.id;
$('#menu-main-menu li.active').removeClass('active');
$('#menu-main-menu li a[href='+ hash +']').parent('li').addClass('active');
window.console.log($(window).scrollTop());
if($(window).scrollTop() < 500){
$('#menu-main-menu li.active').removeClass('active');
}
//$('#menu-main-menu li a').on('click', function(){
//this.disableAll();
//});
},
offset: '30%',
continuous: false
});
//waypoints.disable();
//点击菜单项链接和动画
$('.jumbotron a, #menu-main-menu li a').on('click', function(e) {
e.preventDefault();
//$(waypoints).disable();
//$(waypoints).disableAll();
//waypoints.disable();
//waypoints.disableAll();
$('#menu-main-menu li.active').removeClass('active');
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name="' + this.hash.slice(1) +'"]');
if ($target.length) {
var targetOffset = $target.offset().top - 45;
$('html, body').animate({scrollTop: targetOffset}, 1000);
}
}
});
我意识到waypoints是一个数组,所以尝试了disableAll()和迭代。没有骰子。在此先感谢您的帮助!
答案 0 :(得分:1)
$('.jumbotron a, #menu-main-menu li a').on('click', function(e) {
e.preventDefault();
$('#menu-main-menu li.active').removeClass('active');
//Updated Code
$(waypoints).each(function(){
this.disable();
});
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name="' + this.hash.slice(1) +'"]');
if ($target.length) {
var targetOffset = $target.offset().top - 45;
$('html, body').animate({scrollTop: targetOffset},{
complete: function(){
//Updated Code
$(waypoints).each(function(){
this.enable();
});
}
}, 1000);
}
}
});