This plugin provide buttons that help user scroll smoothly to top and bottom. Via founder of Zepto。
Use following JS code to scroll top in old IE.
$('html, body').animate({scrollTop: 0}, '500');
<button data-am-smooth-scroll class="am-btn am-btn-success">Scroll top</button>
<button id="doc-scroll-to-btm" class="am-btn am-btn-primary">Scroll bottom</button>
<script>
$('#doc-scroll-to-btm').on('click', function() {
var $w = $(window);
$w.smoothScroll({position: $(document).height() - $w.height()});
});
</script>
<button data-am-smooth-scroll="{position: 57, speed: 5000}" class="am-btn am-btn-danger">Slowly scroll to 57px away from top</button>
Add data-am-smooth-scroll
attribute to element.
<button data-am-smooth-scroll class="am-btn am-btn-success">Scroll top</button>
Use position option to scroll to specific position in the page.
<button data-am-smooth-scroll="{position: 189}" class="am-btn am-btn-secondary">...</button>
In order to work correctly on different browsers, please call $().smoothScroll()
method in $(window)
.
$(window).smoothScroll([options])
// Scroll to bottom
$('#my-button').on('click', function() {
var $w = $(window);
$w.smoothScroll({position: $(document).height() - $w.height()});
});
Option | Type | Default | Description |
---|---|---|---|
position | number | 0 | The position of view port when stop scrolling. Default value is `0`, which means scroll to top |
speed | number | 750 ~ 1500 | Scrolling speed in `ms`. Default value is `750 - 1500`, adapted to the distance. |