私はmy website上でこのスクリプトを持っている:jQueryを使用して、リンク固有のスクロールアニメーションを水平および垂直に追加するにはどうすればよいですか?
$(document).ready(function() {
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
$('[href*=#]').each(function() {
if ((filterPath(location.pathname) == filterPath(this.pathname))
&& (location.hostname == this.hostname)
&& (this.hash.replace(/#/,''))) {
var $targetId = $(this.hash),
$targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length
? $targetId
: $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var divOffset = $target.parent().offset().top;
var pOffset = $target.offset().top;
var pScroll = pOffset - divOffset;
$(this).click(function() {
$target.parent().animate({scrollTop: pScroll + 'px'}, 600);
return false;
});
}
}
});
});
それがうまく機能、およびなど上下メインナビゲーションdiv
Sをスクロールが、私はサービスセクション内のdiv
sが左右にスクロールします。また、ポートフォリオセクションにスライダを追加したいのですが、上のコードでは、すべての<a href...>
タグに適用されているので、追加のコードをルール化しています。 mainnav ul
にのみどのように指定しますか?事前