Scrollview
The scrollview component is a UI tool that helps you easily implement common scrollview patterns.
Basic usage
angular
.module('myModule',['mobiscroll-scrollview']) // creating module and setting dependency
.controller('myController', ['$scope', function ($scope) {
$scope.settings = {
theme: 'ios',
itemWidth: 150
};
}]);
<!-- Simple content -->
<div mobiscroll-scrollview>
<div>
Sample content inside a custom horizontall scrollview component
</div>
<div>
Sample content inside a custom horizontall scrollview component
</div>
<div>
Sample content inside a custom horizontall scrollview component
</div>
</div>
<!-- passing options -->
<div mbsc-scrollview="settings">
<div>
Sample content inside a custom horizontall scrollview component
</div>
<div>
Sample content inside a custom horizontall scrollview component
</div>
<div>
Sample content inside a custom horizontall scrollview component
</div>
</mbsc-scrollview>
<ul mobiscroll-scrollview="settings">
<li ng-repeat="item in myExampleData">{{item.text}}</li>
</ul>
Directives
To use the directives of this module you have to set a dependency in you app to 'mobiscroll-scrollview'
Directive | Type | Description |
---|---|---|
mobiscroll-scrollview | Object | Attribute for the Scrollview control. Sets up the mobiscroll initialization object. ex.: "{ theme: 'ios' }" |
For many more examples - simple and complex use-cases - check out the scrollview demos for angularjs.
Options
Name | Type | Default value | Description |
---|---|---|---|
context | String, HTMLElement | 'body' |
The DOM element in which the component is appended and positioned (if not inline). Can be a selector string or a DOM element. |
display | String | 'inline' |
Controls the position of the scrollview. Possible values:
|
itemWidth | Number | undefined |
If layout is 'fixed' , it represents the exact witdh of the items in pixels,
otherwise the minimum width of the items, and the items will be stretched to fill the container width.
|
layout |
String Number |
'liquid' |
Possible values:
|
mousewheel | Boolean | false |
Enables mousewheel / touchpad scroll. |
paging | Boolean | false |
Scroll one page at a time. The page size will be the width of the container. |
snap | Boolean | false |
When the scrollview is scrolled it snaps to the edge of the last visible item which is at the opposite direction of the scroll. |
theme | String | undefined |
Sets the visual appearance of the component.
If it is If the theme for the specific platform is not present, it will default to the Mobiscroll theme. Supplied themes:
Starting from v4.9.0 setting directly the dark version of the theme is deprecated.
Use the themeVariant option instead to control the light / dark appearance of the theme.
Make sure that the theme you set is included in the downloaded package.
|
themeVariant | String | undefined |
Controls which variant of the theme will be used (light or dark). Possible values:
If not set, only the theme setting will determine which theme to use.
To use the option with custom themes, make sure to create two custom themes,
where the dark version has the same name as the light one, suffixed with
The option will not have any effect if the theme option explicitly
sets the dark version of a theme, e.g.
theme: 'ios-dark' .
|
threshold | Number | 10 |
Minimum horizontal movement in pixels before the scrolling starts. |
Setting options dynamically
There are two ways to modify options after initalization
-
Using the option method.
The option method always triggers reinitialization. Most of the settings can be updated only this way, updating without initialization has no effect, because the markup is already generated. If the scroller was visible, the reinitialization hides it and it's not shown again automatically (except in inline display mode).
Here is an example for the dynamic option changeangular .module('demoApp', ['mobiscroll-scrollview']) .controller('demoController', ['$scope', function ($scope) { // Modify options $scope.changeOptions = function () { $scope.myInstance.option({ theme: 'mobiscroll', lang: 'de' }); }; }]);
The markup for the controller<div ng-app="demoApp" ng-controller="demoController"> <input mobiscroll-scrollview mobiscroll-instance="myInstance"/> <button ng-click="changeOptions()">Change options</button> </div>
-
Modify directly the
settings
object.
Useful when changing dynamic settings, which do not need redraw (e.g. readonly, calendar marked days).
// Get instance and modify a setting $scope.myInstance.settings.readonly = true; // Modify settings in an event $scope.settings = { onBeforeShow: function (event, inst) { inst.settings.readonly = true; } };
The markup for the controller<div ng-app="demoApp" ng-controller="demoController"> <input mobiscroll-scrollview="settings" mobiscroll-instance="myInstance"/> </div>
Events
Name | Description | |
---|---|---|
onAnimationEnd(event, inst) | Gets fired when an autonomous scrolling/sliding ends.
Parameters
Example
|
|
onAnimationStart(event, inst) | Gets fired when an autonomous scrolling/sliding is starts.
Parameters
Example
|
|
onGestureEnd(event, inst) | Gets fired when the user ends the scrolling gesture.
Parameters
Example
|
|
onGestureStart(event, inst) | Gets fired when the user ends the scrolling(swiping) gesture.
Parameters
Example
|
|
onInit(event, inst) |
Triggered when the component is initialized.
Parameters
Example
|
|
onItemTap(event, inst) |
Triggered when an item is tapped.
Parameters
Example
|
|
onMarkupReady(event, inst) |
Triggered when the html markup of the component is generated, but it is not yet shown.
It is useful, if you want to make modifications to the markup (e.g. add custom elements), before the positioning runs.
Parameters
Example
|
|
onMove(event, inst) | Gets fired when an autonomous scrolling/sliding ends.
Parameters
Example
|
Methods
Name | Description | |
---|---|---|
getInst() |
Returns the object instance.
Returns: Object
ExampleMethods can be called on an instance. For more details see calling methods
|
|
navigate(item [, toggle ] [, animTime]) |
Scrolls the scrollview to the specified item.
Parameters
ExampleMethods can be called on an instance. For more details see calling methods
|
|
next([toggle]) | Scrolls the scrollview to the next item.
Parameters
ExampleMethods can be called on an instance. For more details see calling methods
|
|
option(options) |
Sets one or more options for the component.
Parameters
ExampleMethods can be called on an instance. For more details see calling methods
|
|
prev([toggle]) | Scrolls the scrollview to the previous item.
Parameters
ExampleMethods can be called on an instance. For more details see calling methods
|
|
refresh() |
Recalculate dimensions needed for scrolling.
ExampleMethods can be called on an instance. For more details see calling methods
|
|
tap(el, handler) |
Attaches the handler function to the tap event of element el .
Parameters
ExampleMethods can be called on an instance. For more details see calling methods
|
Localization
Name | Type | Default value | Description |
---|---|---|---|
lang | String | 'en-US' |
Language of the component. Based on the language string the component loads the language based default settings from the
language modules.
Supported languages:
|
rtl | Boolean | false |
Right to left display. |