jQueryとフラグメント識別子を使用して、ユーザーが現在1ページのサイトのどの部分を見ているかに応じて状態を変更しています。
私はついにこれを機能させることができましたが、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);