Jquery 不要加上“;主动的;用于菜单平滑滚动的类
当我的站点菜单仅获取“#”作为“#关于”时,则添加类“活动”并平滑滚动工作,但当菜单获取完整站点链接为“”时,则无法添加类“活动”且平滑滚动不工作 我的代码:Jquery 不要加上“;主动的;用于菜单平滑滚动的类,jquery,Jquery,当我的站点菜单仅获取“#”作为“#关于”时,则添加类“活动”并平滑滚动工作,但当菜单获取完整站点链接为“”时,则无法添加类“活动”且平滑滚动不工作 我的代码: /* ============================================== Smooth Scrolling =============================================== */ var scrollElement = 'html, body', $scrollElement
/* ==============================================
Smooth Scrolling
=============================================== */
var scrollElement = 'html, body',
$scrollElement;
$(function() {
$('html, body').each(function () {
if(wWidth > mobileRes) {
var initScrollLeft = $(this).attr('scrollLeft');
$(this).attr('scrollLeft', initScrollLeft + 1);
if ($(this).attr('scrollLeft') == initScrollLeft + 1) {
scrollElement = this.nodeName.toLowerCase();
$(this).attr('scrollLeft', initScrollLeft);
return false;
}
}
});
$scrollElement = $(scrollElement);
});
$(function() {
var $sections = $('section.section');
$sections.each(function() {
var $section = $(this);
var hash = '#' + this.id;
$('a[href="' + hash + '"]').click(function(event) {
moving = true;
if(wWidth > mobileRes) {
$scrollElement.stop().animate({
scrollLeft: $section.offset().left
}, 1200, 'easeOutCubic', function() {
window.location.hash = hash;
});
} else {
$scrollElement.stop().animate({
scrollTop: $section.offset().top
}, 1200, 'easeOutCubic');
}
$('nav#main-nav a').removeClass('active');
if($(this).hasClass('content-menu-link')) {
var link = $(this).attr('href');
$('a[href="' + hash + '"]').addClass('active');
} else {
$(this).addClass('active');
}
var trigger = $('#responsive-nav'),
menu = $('#main-nav ul');
if(trigger.hasClass('nav-visible')) {
menu.slideToggle();
trigger.toggleClass('nav-visible');
}
event.preventDefault();
});
});
});
function setInitActiveMenu() {
var hash = window.location.hash;
$('a[href="' + hash + '"]').addClass('active');
}
setInitActiveMenu();
请帮帮我。我能做什么。在您的代码中
$('a[href="' + hash + '"]')
与
用作滚动动画的选择器,用于确定滚动到何处以及将哪个菜单元素设置为活动
因此,使用您所谓的完整站点链接(
http://example.com#hash
)不起作用。为什么要将您称之为完整站点链接的内容放在菜单中?
var hash = '#' + this.id;