我有一个脚本,用于在用户向下滚动页面时更新固定菜单。在前端工作是没有错误的,但是现在我已经开始研究WordPress集成了,我得到了一个奇怪的错误消息,我很难理解。jQuery语法错误,无法识别的表达式
一个加载页面是好的,但只要我向下滚动出现错误。
这是jsfiddle。 http://jsfiddle.net/2k4Eq/ 它似乎与完整的URL有关,因为它只与#whatWeDo一起使用。
Syntax error, unrecognized expression: http://localhost:8888/sitename/#whatWeDo
从jQuery的
Sizzle.error = function(msg) {
throw new Error("Syntax error, unrecognized expression: " + msg);
};
谢谢!
// Update menu position on scroll
$(function() {
function updateMenu() {
var lastId,
mainMenu = $("#main-menu ul"),
mainMenuInnerHeight = mainMenu.outerHeight(),
mainMenuItems = $("#main-menu.navigation ul").find(".section-item a"),
sliderButtons = $("#call-to-actions "),
sliderLinks = sliderButtons.find("a.button.white"),
// Anchors relating to links
scrollItems = mainMenuItems.map(function(){
var item = $(this).attr("href");
if (item.length) { return item; }
});
console.log(scrollItems);
mainMenuItems.bind("click",scrollDown);
sliderLinks.bind("click",scrollDown);
function scrollDown(e){
e.preventDefault();
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top;
$("html, body").stop().animate({
scrollTop: offsetTop
}, 600);
$("#main-mobile-menu").hide();
}
$(window).scroll(function(){
var fromTop = $(this).scrollTop()+mainMenuInnerHeight;
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
mainMenuItems
.parent().removeClass("active")
.end().filter("[href=#"+id+"]").parent().addClass("active");
}
});
}
updateMenu();
$(window).resize(function(){
updateMenu();
});
});
@Curt我想你的答案也可能是问题, –
谢谢你的回复!不幸的是,似乎没有解决这个问题。在控制台中,错误出现在jQuery文件中。现在我已经没有信心了,我可以看到更多的错误。我已经更新了我的q。 – Rich
@查看更新...它是由作者删除的另一个答案的副本 –