2016-08-05 2 views
0

웹 사이트를 구축하려고하는데 아주 멋진 끈끈한 헤더가 있으며 부트 스트랩을 사용하지 않고 일종의 스파이 스파이 효과를 얻으려고합니다. viewd가 탐색중인 현재 섹션이 활성 클래스로 강조 표시되면 좋겠다.자바 스크립트 스크롤 강조 표시가 작동하지 않습니다.

문제는 0 jquery 지식을 가지고 있으므로 YouTube 비디오에서 일부 코드를 복사했지만 효과적으로 구현할 수 없습니다. 누군가이 탐색 코드를 강조 표시하여 현재 탐색중인 섹션과 사용자가 다른 섹션으로 스크롤하여 탐색 막대에서 해당 섹션이 강조 표시되도록이 쿼리 코드를 수정할 수 있습니까?

시 - 내가 반복, 나는

가 여기 내 코드 펜 링크 http://codepen.io/anon/pen/bZmRZN

Any help would be amazing! 
+0

1)에 그것을 시도, 2) 때를 codepen에서 하나의 명백한 오류가 수정되었습니다. 20 개가 더 갑자기 나타났습니다. 3) 브라우저 개발자 도구 콘솔에서 어떤 오류가 발생했는지 4) ** "스크롤 스파이 같은 효과가 있는지" 방법. 그리고 5)'누군가가이 쿼리 코드를 고칠 수 있을까요? '- 실제로 질문에'query code'라는 글을 게시하고 코드에서 수정하고자하는 것을 설명 할 수 있습니까? –

+0

"scrollspy"가 잘 동작합니다. – yuriy636

답변

0

당신이 (function() { 전에 jQuery를 호출하기위한 $을 넣어 깜빡입니다 아무것도 부트 스트랩의 xD와 싶지 않아요. 이 조각을 잘 보여 나던하지만 난 내 서버에 그것을 시도하고 잘 작동하지만 ~ 서버 : 당신의 codepen가로드되지 않습니다

$(function() { 
 
\t var navLinks = $('nav ul li a'), 
 
\t \t \t navH = $('nav').height(), 
 
\t \t \t section = $('section'), 
 
\t \t \t documentEl = $(document); 
 

 
\t documentEl.on('scroll', function() { 
 
\t \t \t var currentScrollPos = documentEl.scrollTop(); 
 

 
\t \t \t section.each(function() { 
 
\t \t \t \t \t var self = $(this); 
 
\t \t \t \t \t if (self.offset().top < (currentScrollPos + navH) && (currentScrollPos + navH) < (self.offset().top + self.outerHeight())) { 
 
\t \t \t \t \t \t \t var targetClass = '.' + self.attr('class') + '-marker'; 
 
\t \t \t \t \t \t \t navLinks.removeClass('active'); 
 
\t \t \t \t \t \t \t $(targetClass).addClass('active'); 
 
\t \t \t \t \t } 
 
\t \t \t }); 
 

 
\t }); 
 
})();
@charset "utf-8"; 
 
* { 
 
    /*reset*/ 
 
    background: none repeat scroll 0 0 transparent; 
 
    border: medium none; 
 
    border-spacing: 0; 
 
    font-size: 16px; 
 
    font-weight: normal; 
 
    line-height: 1.42rem; 
 
    list-style: none outside none; 
 
    margin: 0; 
 
    padding: 0; 
 
    text-align: left; 
 
    text-decoration: none; 
 
    text-indent: 0; 
 
    box-sizing: border-box; 
 
} 
 

 
html, body, div, span, applet, object, iframe, 
 
h1, h2, h3, h4, h5, h6, p, blockquote, pre, 
 
a, abbr, acronym, address, big, cite, code, 
 
del, dfn, em, img, ins, kbd, q, s, samp, 
 
small, strike, strong, sub, sup, tt, var, 
 
b, u, i, center, 
 
dl, dt, dd, ol, ul, li, 
 
fieldset, form, label, legend, 
 
table, caption, tbody, tfoot, thead, tr, th, td, 
 
article, aside, canvas, details, embed, 
 
figure, figcaption, footer, header, hgroup, 
 
menu, nav, output, ruby, section, summary, 
 
time, mark, audio, video { 
 
\t margin: 0; 
 
\t padding: 0; 
 
\t border: 0; 
 
\t font-size: 100%; 
 
\t font: inherit; 
 
\t vertical-align: baseline; 
 
} 
 

 
/* HTML5 display-role reset for older browsers */ 
 
article, aside, details, figcaption, figure, 
 
footer, header, hgroup, menu, nav, section { 
 
\t display: block; 
 
} 
 
body { 
 
\t line-height: 1; 
 
} 
 
ol, ul { 
 
\t list-style: none; 
 
} 
 
blockquote, q { 
 
\t quotes: none; 
 
} 
 
blockquote:before, blockquote:after, 
 
q:before, q:after { 
 
\t content: ''; 
 
\t content: none; 
 
} 
 
table { 
 
\t border-collapse: collapse; 
 
\t border-spacing: 0; 
 
} 
 
button{ 
 
    -webkit-appearance: none !important; 
 
} 
 
a{ 
 
    -webkit-appearance: none; 
 
} 
 
/*End Reset*/ 
 

 
/*Fonts*/ 
 
@font-face { 
 
    font-family: 'bebas_neuebold'; 
 
    src: url('../fonts/bebasneue_bold-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue_bold-webfont.woff') format('woff'); 
 
} 
 
@font-face { 
 
    font-family: 'bebas_neuebook'; 
 
    src: url('../fonts/bebasneue_book-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue_book-webfont.woff') format('woff'); 
 
} 
 
@font-face { 
 
    font-family: 'bebas_neuelight'; 
 
    src: url('../fonts/bebasneue_light-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue_light-webfont.woff') format('woff'); 
 
} 
 
@font-face { 
 
    font-family: 'bebas_neue_regularregular'; 
 
    src: url('../fonts/bebasneue_regular-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue_regular-webfont.woff') format('woff'); 
 
} 
 
@font-face { 
 
    font-family: 'bebas_neuethin'; 
 
    src: url('../fonts/bebasneue_thin-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue_thin-webfont.woff') format('woff'); 
 
} 
 
@font-face { 
 
    font-family: 'bebas_neueregular'; 
 
    src: url('../fonts/bebasneue-webfont.woff2') format('woff2'), 
 
     url('../fonts/bebasneue-webfont.woff') format('woff'); 
 
} 
 
.bebas-bold{ 
 
\t font-family: bebas_neuebold !important; 
 
    letter-spacing: 0.05em; 
 
} 
 
.bebas-book{ 
 
\t font-family: bebas_neuebook !important; 
 
} 
 
.bebas-light{ 
 
\t font-family: bebas_neuelight !important; 
 
    letter-spacing: 0.05em; 
 
} 
 
.bebas-thin{ 
 
    font-family: bebas_neuethin !important; 
 
    letter-spacing: 0.05em; 
 
} 
 
.bebas-reg{ 
 
\t font-family: bebas_neue_regularregular !important; 
 
    letter-spacing: 0.05em; 
 
} 
 
/*End fonts*/ 
 
body { 
 
    font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
 
    font-weight: 300; 
 
    background-color: #505050; 
 
    padding: 0px; 
 
    margin: 0px; 
 
} 
 

 
/*Header*/ 
 
#navwrapper{ 
 
    width: 100%; 
 
    position: fixed; 
 
    z-index: 1; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
} 
 
li img { 
 
\t height:95px; 
 
\t width:95px; 
 
} 
 

 
ul{ 
 
    display: table; 
 
    margin: 0 auto; 
 
} 
 

 
ul.topnav { 
 
    padding: 0; 
 
    overflow: hidden; 
 
} 
 

 
.toggleNavButton { 
 
    transition-duration: 0.5s; 
 
    width: 40px; 
 
    height: 2px; 
 
    background-color: black; 
 
    position: absolute; 
 
    /*left: 50%;*/ 
 
    top: 25px; 
 
    margin-left: 20px; 
 
    border-radius: 2px; 
 
} 
 
.toggleNavButton:before, 
 
.toggleNavButton:after { 
 
    border-radius: 2px; 
 
    transition-duration: 0.5s; 
 
    content: ""; 
 
    position: absolute; 
 
    top: 10px; 
 
    left: 0; 
 
    background-color: black; 
 
    width: 40px; 
 
    height: 2px; 
 
} 
 
.toggleNavButton:after { 
 
    top: 20px; 
 
} 
 
.toggleNavButton.active { 
 
    width: 0; 
 
} 
 
.toggleNavButton.active:after { 
 
    top: 10px; 
 
    transform: rotate(45deg); 
 
    -webkit-transform: rotate(45deg); 
 
} 
 
.toggleNavButton.active:before { 
 
    transform: rotate(-45deg); 
 
    -webkit-transform: rotate(-45deg); 
 
} 
 
/* Float the list items side by side */ 
 
nav ul.topnav li { 
 
    float: left; 
 
} 
 

 
.padnav{ 
 
    padding: 0px 35px 0px 35px; 
 
    margin-top:35px; 
 
} 
 

 
/* Style the links inside the list items */ 
 
nav ul li a { 
 
    display: block; 
 
    color: #1b1b1b; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    transition: 0.5s; 
 
    font-size: 1.5em; 
 
    padding: 5px; 
 
} 
 

 
/* Change background color of links on hover */ 
 
nav ul li.padnav a:hover { 
 
    -webkit-transition: 0.2s; /* Safari */ 
 
    transition: 0.2s; 
 
    border-bottom: 5px solid #2098D1; 
 

 
} 
 

 
.active{ 
 
    -webkit-transition: 0.1s; /* Safari */ 
 
    transition: 0.1s;; 
 
    border-bottom: 5px solid #2098D1; 
 
} 
 

 
.hide{ 
 
    display: none; 
 
    width: 0px; 
 
    height: 0px; 
 
} 
 

 
nav{ 
 
    position: fixed; 
 
} 
 

 
/* Hide the list item that contains the link that should open and close the topnav on small screens */ 
 
ul.topnav li.icon { 
 
    display: none; 
 
} 
 

 
/* When the screen is less than 680 (changed to 770 to accomodate) pixels wide, hide all list items, except for the first one ("Home"). Show the list item that contains the link to open and close the topnav (li.icon) */ 
 
@media screen and (max-width:767px) { 
 
    ul.topnav li:not(:first-child) { 
 
    display: none; 
 
    } 
 

 
    ul.topnav li:nth-child(1){ 
 
    display: inline-block !important; 
 
    width: auto !important; 
 
    height: auto !important; 
 
    } 
 

 
    ul.topnav li.icon { 
 
    float: right; 
 
    display: inline-block; 
 
    width: 60px; 
 
    } 
 
    ul.topnav li{ 
 
    padding: 0px !important; 
 
    } 
 
    ul.topnav a{ 
 
    margin-top: 25px !important; 
 
    margin-right: 25px !important; 
 
    padding: 0px !important; 
 
    } 
 

 
    li img { 
 
    display: none; 
 
    } 
 

 
    .topnav{ 
 
    width: 100% !important; 
 
    } 
 

 
    #navhit{ 
 
    height: 50px; 
 
    width: 80px; 
 
    float: right; 
 
    display: inline-block; 
 
    margin-top: -8px; 
 
    } 
 

 
    li.padnav{ 
 
    padding: 0px !important; 
 
    margin-top: 0px !important; 
 
    } 
 

 
    ul.topnav li.padnav a:hover { 
 
    border: none !important; 
 
    } 
 

 
    #navwrapper{ 
 
    padding-bottom: 20px; 
 
    } 
 
} 
 
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens */ 
 
@media screen and (max-width:767px) { 
 
    ul.topnav.responsive {position: relative;} 
 
    ul.topnav.responsive li.icon { 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    } 
 
    ul.topnav.responsive li { 
 
    float: none; 
 
    display: inline; 
 
    } 
 
    ul.topnav.responsive li a { 
 
    display: block; 
 
    text-align: left; 
 
    } 
 
} 
 
/*sections*/ 
 
section { 
 
    width: 100%; 
 
    padding: 0 7%; 
 
    display: table; 
 
    margin: 0; 
 
    max-width: none; 
 
    height: 100vh; 
 
} 
 

 
section.landing{ 
 
    background-color: #f39c12; 
 
} 
 

 
section.about{ 
 
    background-color: #9b59b6; 
 
} 
 

 
section.project{ 
 
    background-color: #2ecc71; 
 
} 
 

 
section.blog{ 
 
    background-color: #95a5a6; 
 
} 
 

 
section.contact{ 
 
    background-color: #f1c40f; 
 
} 
 

 
.landing{ 
 
    height: 95vh; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="navwrapper"> 
 
\t <nav class="navbar bebas-reg container"> 
 
\t \t <ul class="topnav" id="myTopnav"> 
 
\t \t \t <li class="padnav"><a href="about.html" class="about-marker active">About</a></li> 
 
\t \t \t <li class="padnav"><a href="projects.html" class="proj-marker">Projects</a></li> 
 
\t \t \t <li class="logo"><img src="img/logo-black.png"></img></li> 
 
\t \t \t <li class="padnav"><a href="contact" class="contact-marker">Contact</a></li> 
 
\t \t \t <li class="padnav"><a href="blog" class="blog-marker">Blog</a></li> 
 
\t \t </ul> 
 
\t </nav> 
 
</div> 
 

 

 
<section class="landing"> 
 
\t <h1> landing </h1> 
 
</section> 
 

 
<section class="about"> 
 
\t <h1> about </h1> 
 
</section> 
 

 
<section class="proj"> 
 
\t <h1> proj </h1> 
 
</section> 
 

 
<section class="contact"> 
 
\t <h1> contact </h1> 
 
</section> 
 

 
<section class="blog"> 
 
\t <h1> blog </h1> 
 
</section>

+0

고맙습니다! 나는이 일로 너무 많이 울었다. 당신의 설명과 코드는 훌륭했습니다 :) –

관련 문제