如何使用缓动效果滚动页面? 我希望当我点击菜单然后通过滚动缓动效果来调用其ID部分
<body data-spy="scroll" data-target="#myNavbar" data-offset="0">
<nav id="myNavbar" class="navbar navbar-default" role="navigation">
<div class="container">
<h1 class="navbar-brand align" href="#">ashish</h1>
<!-- Brand and toggle get grouped for better mobile display -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-
target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#homesection">Home</a></li>
<li><a href="#ourServices">What i do?</a></li>
<li><a href="#Portfolio">Portfolio</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</nav>
在此先感谢plz帮助我
答案 0 :(得分:0)
像这样:
<a href="#Portfolio" onClick="scrollTo('Portfolio', event)">Portfolio</a>
部分:
<div id="Portfolio">....</div>
JS:
function scrollTo(element, event) {
event.preventDefault();
event.stopPropagation();
$('html, body').animate({ 'scrollTop' : $('#' + element).offset().top + 'px' }, 1000);
}
你需要jQuery。
干杯