我正在使用 jQuery 和片段标识符来创建状态更改,具体取决于用户当前正在查看的单页站点的哪个部分。
我终于让它工作了,但由于 Safari 和 Chrome 都不会显示片段标识符,我无法将它变成一个变量,因此系统崩溃了。
有没有办法专门针对 WebKit 浏览器强制执行此操作或以其他方式访问片段?
编辑:在下面添加代码
(function($){
$.fn.sectionMove = function() {
return this.each(function() {
$(this).click(function() {
if(window.location.hash){
var $hash = window.location.hash;
} else if (!window.location.hash) {
var $hash = '#section1';
}
$n = $hash.substring($hash.length-1,$hash.length);
$("div#headerNav ul li:nth-child(" + $n + ") a").removeClass('on');
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1000,'easeInOutExpo', function(){
var $hash = window.location.hash;
$n = $hash.substring($hash.length-1,$hash.length);
$("div#headerNav ul li:nth-child(" + $n + ") a").addClass('on');
});
event.preventDefault();
});
});
};
})(jQuery);