Amaze UI 2.4

JavaScript

Amaze UI styled jQuery plugins and utils.

Smooth Scroll


This plugin provide buttons that help user scroll smoothly to top and bottom. Via founder of Zepto

This plugin is not supported by IE 9 and older version. Please find other replacement if required.

Use following JS code to scroll top in old IE.

$('html, body').animate({scrollTop: 0}, '500');

Examples

Scroll top

<button data-am-smooth-scroll class="am-btn am-btn-success">Scroll top</button>

Scroll bottom

<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>

Options

<button data-am-smooth-scroll="{position: 57, speed: 5000}" class="am-btn am-btn-danger">Slowly scroll to 57px away from top</button>

Usage

Using Data API

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>

Using Javascript

Methods

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()});
});

Options

OptionTypeDefaultDescription
positionnumber0The position of view port when stop scrolling. Default value is `0`, which means scroll to top
speednumber750 ~ 1500Scrolling speed in `ms`. Default value is `750 - 1500`, adapted to the distance.
侧栏导航
Amaze UI 微信
在微信上关注我们