可滚动网页导航

时间:2015-06-08 23:59:29

标签: javascript css button navigation highlight

我制作了一个可滚动的网页。我想要做的是在按下按钮时以及当我从中查看内容时突出显示按钮。当我向下滚动更多时,必须触发导航中的下一个按钮。这是我的代码:

.container {
  width: 100%;
  height: 100px;
  position: relative;
  font-family: 'Trebuchet Ms';
}

.bg {
  background: #000;
  width: 100%;
  height: 100px;
  opacity: 0;
}

.show {
  opacity: 0.6;
}

.transition {    
  -webkit-transition: all 1s ease-in-out;
	-moz-transition: all 1s ease-in-out;
	-o-transition: all 1s ease-in-out;
	transition: all 1s ease-in-out;
}

.fixed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1;
}

ul {
  height: 200px;
  margin: -70px auto 0 auto;
  width: 810px;
}

li {
  float: left; 
  list-style: none;
  margin: 10px 20px;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: #000;
}

a {
  text-align: center;
  font-size: 15px;
  color: #CFB547;
  font-weight: bold;
  text-decoration: none;
  letter-spacing: 5px;
  
  position: relative;
  z-index: 1;
  margin: 0 auto;
  display: block;
}

a:hover {
  color: #a6a6a6;
  text-shadow: 1px 1px 1px 1px;
  text-decoration: none;
}

.down {
  top: 150px;
}

.up {
  top: 1800px;
}
<section id="top">
<div id="top" class="container">
<div class="fixed">
<div class="bg transition">
</div>
<ul>
<li><a href="#top">Crystal Beach</a></li>
<li><a href="#about">Apartments</a></li>
<li><a href="#blanktwo">Facilities</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</section>

$(window).scroll(function() {
// 100 = The point you would like to fade the nav in.
  
	if ($(window).scrollTop() > 100 ){
    
 		$('.bg').addClass('show');
    
  } else {
    
    $('.bg').removeClass('show');
    
 	};   	
});

$('.scroll').on('click', function(e){		
		e.preventDefault()
    
  $('html, body').animate({
      scrollTop : $(this.hash).offset().top
    }, 1500);
});

1 个答案:

答案 0 :(得分:0)

在这里你https://jsfiddle.net/mekwall/up4nu/

"format es6";
[1,2,3,4].map((i)=>i*i);