助けてくれてありがとう、初心者であることを許してください。答えは非常に単純かもしれません。
個人サイト「EthanGreenspan.com」で「 ScrollNav.js 」という JQuery プラグインを使用しようとしています。
このプラグインを使用して、ユーザーがセクションをクリックしてスクロールできるインタラクティブな目次を備えたシンプルな左ペインを作成したいと考えています。JSFiddle (下部のリンク) でわかるように、左ペインの は ScrollNav サイトのようには機能しません。
これは、目次として使用したい の HTML です。
<div class="leftpane" class="main" role="main">
<nav class="scroll-nav" role="navigation">
<span class="scroll-nav-heading">Sections</span>
<ol class="scroll-nav-list">
<li class="scroll-nav-item active top">
<a href="#jumpNav-0" class="scroll-nav-link">Top</a></li>
<li class="scroll-nav-item active Current Work">
<a href="#jumpNav-1" class="scroll-nav-link"></a>Current Work</li>
<li>Photography</li>
<li>Consulting</li>
<li>Blog</li>
<li>Contact Me</li>
</ol>
これはJqueryです(JSFiddle用にインラインに配置しました)
<script>
$('.body').scrollNav({
sections: 'h3',
titletext: 'Scroll To',
fixedmargin: 40,
animation: true,
})
</script>
最後に、ScrollNav JQuery プラグインを次に示します。
(function(e){e.fn.scrollNav=function(t){e("body").addClass("sn-loading");var n={sections:"h3",titleText:"Scroll To",fixedMargin:40,animated:!0,speed:500,showHeadline:!0,showTopLink:!0,location:"insertBefore"};e.extend(n,t);var r=[],i=this,s=i.find(n.sections),o=e("<nav />",{"class":"scroll-nav",role:"navigation"}),u=function(){if(n.showTopLink===!1)return;var e=i.attr("id"),t=i.offset().top;if(e)r.push({id:e,offset:t,text:"Top"});else{i.attr("id","jumpNav-0");r.push({id:"jumpNav-0",offset:t,text:"Top"})}},a=function(){s.each(function(t){var n="jumpNav-"+(t+1),i=e(this).offset().top,s=e(this).text();e(this).attr("id",n);r.push({id:n,offset:i,text:s})})},f=function(){var t=e("<span />",{"class":"scroll-nav-heading",text:n.titleText}),i=e("<ol />",{"class":"scroll-nav-list"});e.each(r,function(t){var n=t===0?e("<li />",{"class":"scroll-nav-item active"}):e("<li />",{"class":"scroll-nav-item"}),r=e("<a />",{href:"#"+this.id,"class":"scroll-nav-link",text:this.text});i.append(n.append(r))});n.showHeadline===!0?o.append(t).append(i):o.append(i)},l=function(){var t=o.offset().top;e(window).resize(function(){e.each(r,function(){this.offset=e("#"+this.id).offset().top})});e(window).scroll(function(){var i=e(window).scrollTop(),s=e(window).height()*.5;i>t-n.fixedMargin?o.addClass("fixed"):o.removeClass("fixed");e.each(r,function(){if(this.offset>i-n.fixedMargin&&this.offset<i+s){o.find("li").removeClass("active");o.find('a[href="#'+this.id+'"]').parents("li").addClass("active")}})})};if(i.length!==0){u();a();f()}i.length!==0&&s.length!==0?o[n.location](i):i.length===0?console.log("Build failed, scrollNav could not find '"+i.selector+"'"):s.length===0&&console.log("Build failed, scrollNav could not find any '"+n.sections+"'s inside of '"+i.selector+"'");l();n.animated===!0&&e(".scroll-nav-link").click(function(){var t=e(this).attr("href"),r=e(t).offset().top;e("html:not(:animated),body:not(:animated)").animate({scrollTop:r-40},n.speed);return!1});e("body").removeClass("sn-loading").addClass("sn-active")}})(jQuery);
私は JQuery の基本を理解していますが、本当にあなたの助けが必要です!
これは、私の HTML/CSS/JSを使用したJSFiddleへのリンクです。
よろしくお願いします!