你好 !
如果我正在工作,我必须为公司创建一个网站:)
我的问题 :
我用 Wordpress 创建了http://webl.eu/wordpress/,它是“二十三”的子主题。
当用户滚动到相应的元素时,我想进行导航 li 或更改。我找到了这个脚本:
(function($){
var sections = [];
var id = false;
var $navbar = $('#navigation_desktop .navigation');
var $navbara = $('a', $navbar);
$navbara.click(function(e){
e.preventDefault();
$('html, body').animate({
scrollTop: $($(this).attr('href')).offset().top - $navbar.height()
});
hash($(this).attr('href'));
});
$navbara.each(function(){
sections.push($($(this).attr('href'))); // !!!erreur ici!!!
});
console.log(sections);
$(window).scroll(function(e){
var scrollTop = $(this).scrollTop() + ($(window).height() / 2)
for(var i in sections){
var section = sections[i];
if (scrollTop > section.offset().top) { // !!!erreur ici!!!
scrolled_id = section.attr('id');
}
}
if (scrolled_id !== id) {
id = scrolled_id
$navbara.removeClass('current');
$('a[href="#' + id + '"]', $navbar).addClass('current');
}
});
})(jQuery);
hash = function(h) {
if (history.pushState) {
history.pushState(null, null, h);
}else{
location.hash = h;
}
}
我认为它应该工作......但它没有:(
谢谢,