
jquery.smooth-scroll.js 可以轻松实现同一页面链接的平滑滚动。
主要js
<script src="js/jquery.min.js" type="text/javascript"></script> <script src="js/jquery.smooth-scroll.js" type="text/javascript"></script> <script> $(document).ready(function () { $('nav li a').smoothScroll(); }); </script>
更多参数说明
offset: 0,
// one of 'top' or 'left'
direction: 'top',// only use if you want to override default behavior or if using $.smoothScroll
scrollTarget: null,// automatically focus the target element after scrolling to it
autoFocus: false,// string to use as selector for event delegation
delegateSelector: null,// fn(opts) function to be called before scrolling occurs.
// `this` is the element(s) being scrolled
beforeScroll: function() {},// fn(opts) function to be called after scrolling occurs.
// `this` is the triggering element
afterScroll: function() {},// easing name. jQuery comes with "swing" and "linear." For others, you'll need an easing plugin
// from jQuery UI or elsewhere
easing: 'swing',// speed can be a number or 'auto'
// if 'auto', the speed will be calculated based on the formula:
// (current scroll position - target scroll position) / autoCoefficient
speed: 400,// autoCoefficent: Only used when speed set to "auto".
// The higher this number, the faster the scroll speed
autoCoefficient: 2,// $.fn.smoothScroll only: whether to prevent the default click action
preventDefault: true