This is just a wrapper as an Ember component around perfect-scrollbar.
ember install ember-perfectscroll
ember g ember-perfect-scroll
You can pass its options as they are defined for perfect-scrollbar
plugin
CSS classes a provided by perfect-scrollbar
ps-container
ps-active-x
ps-active-y
Addon provides only ps-content
class alongside with default classes.
As an example you can use dummy app for tests under tests/dummy
bower install perfect-scrollbar
perfect-scrollbar dispatches its own custom events. For each event type; the current value of the scroll position for the corresponding axis is dispatched as the first parameter of the event.
In summary; the value
dispatched for
ps-scroll-y
, ps-scroll-up
, ps-scroll-down
, ps-y-reach-start
, and ps-y-reach-end
events is the current scroll
position of the vertical scroll bar; where as it is the current scroll position of the horizontal scroll bar for
ps-scroll-y
, ps-scroll-up
, ps-scroll-down
, ps-y-reach-start
, and ps-y-reach-end
events.
This event fires when the y-axis is scrolled in either direction.
This event fires when the x-axis is scrolled in either direction.
This event fires when scrolling upwards.
This event fires when scrolling downwards.
This event fires when scrolling to the left.
This event fires when scrolling to the right.
This event fires when scrolling reaches the start of the y-axis.
This event fires when scrolling reaches the end of the y-axis (useful for infinite scroll).
This event fires when scrolling reaches the start of the x-axis.
This event fires when scrolling reaches the end of the x-axis.
To use them just pass the event name and bound your action
perfect-scrollbar requires to call update
in case the size
of the container or the content changes. In order to enable calling update
for underlying perfect scroll component you
should make use of PerfectScrollBarController
mixin. This mixin contains a method called updatePerfectScroll
that
takes an optional scrollId
parameter (which you can pass to the perfect-scroll
within the template). If scrolldId
parameter is omitted; the first perfect-scroll
being controlled is updated. Please take a look at the following code
snippet in order to update the scroll bar programmatically in case an update is needed due to content or container size
change.
import Ember from 'ember';
import PerfectScrollController from 'ember-perfect-scroll/mixins/perfect-scroll-controller';
export default Ember.Controller.extend(PerfectScrollController,{
actions: {
yReachEnd(scrollPosition) {
/* eslint-disable no-console */
console.log(`ps-y-reach-end - ${scrollPosition}`);
},
scrollX(scrollPosition) {
/* eslint-disable no-console */
console.log(`ps-scroll-x - ${scrollPosition}`);
},
scrollY(scrollPosition) {
/* eslint-disable no-console */
console.log(`ps-scroll-y - ${scrollPosition}`);
},
changeContainerHeightTo500() {
Ember.$('.ps-content').height(500);
this.updatePerfectScroll();
},
performScrollTo150_150() {
this.performScroll(150, 150);
},
}
});
PerfectScrollController
mixin needs to be imported from ember-perfect-scroll/mixins/perfect-scroll-controller
and
should be injected to a relevant construct such as controller (as in the snippet above), a route or a component.
perfect-scroll
's lifeCycleEventOccurred
event needs to be handled via
lifeCycleEventOccurred=(action 'lifeCycleEventOccurred')
declaration within the template. By this way; the mixin's
relevant code gets notified about initialization and destroy phases of perfect-scroll
and you should be able to call
updatePerfectScroll
when needed.
Another useful method provided by PerfectScrollController
mixin is performScroll
. As the name implies, scrolling to
desired scrollbar positions should be performed via this method. It takes three arguments:
scrollLeft
: new scroll position for horizontal scrollbar. Passundefined
if no update is desired for x-axis.scrollTop
: new scroll position for vertical scrollbar. Passundefined
if no update is desired for y-axis.scrolldId
: Optional parameter to identify theperfect-scroll
to be scrolled. Firstperfect-scrollbar
being controlled is applied scrolling if this parameter is omitted.
The scroll speed applied to mousewheel event. Default: 1
If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element. Default: false
If this option is true, when the scroll reaches the end of the side, touch scrolling will be propagated to parent element. Default: true
When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels. Default: null
When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels. Default: null
When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar. Default: false
When set to true, the scroll works with arrow keys on the keyboard. The element is scrolled only when the mouse cursor hovers the element. Default: true
When set to true, the scroll bar in X axis will not be available, regardless of the content width. Default: false
When set to true, the scroll bar in Y axis will not be available, regardless of the content height. Default: false
The number of pixels the content width can surpass the container width without enabling the X axis scroll bar. Allows some "wiggle room" or "offset break", so that X axis scroll bar is not enabled just because of a few pixels. Default: 0
The number of pixels the content height can surpass the container height without enabling the Y axis scroll bar. Allows some "wiggle room" or "offset break", so that Y axis scroll bar is not enabled just because of a few pixels. Default: 0
When set to true, it uses innerWidth
and innerHeight
for the container size instead of width
and height
. When your container element has non-zero padding and the scrollbar layout looks weird, this option can be helpful.
Default: false
A string. It's a class name added to the container element. The class name is prepended with ps-theme-
. So default theme class name is ps-theme-default
. In order to create custom themes with scss use ps-container($theme)
mixin, where $theme
is a scss map.
Default: 'default'
Example 1:
Add theme
parameter:
Ps.initialize(container, {
theme: 'my-theme-name'
});
Get more information about perfect-scrollbar. For more information on using ember-cli, visit http://www.ember-cli.com/.