General Calendar Cards Color Date & Time Event Calendar Forms Grid Layout Image Listview Measurement Navigation Number Numpad Option List Page Popup Range Scroller Scrollview Select Timer Timespan Treelist Tools Accessibility

Scrollview

The scrollview component is a UI tool that helps you easily implement common scrollview patterns.

Basic usage

Here is an example for the Scrollview component
angular
.module('myModule',['mobiscroll-scrollview']) // creating module and setting dependency
.controller('myController', ['$scope', function ($scope) {
    $scope.settings = { 
        theme: 'ios',
        itemWidth: 150
    };        
}]);
The markup for the controller
<!-- 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>
Dynamic items
<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' }"

Options

Name Type Default value Description
context String or HTMLElement 'body' Context in which mobiscroll 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:
  • 'inline' - Stay in the normal document flow.
  • 'top' - Fixed to top.
  • 'bottom' - Fixed to bottom.
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:
  • 'liquid' - The number of displayed items will be calculated from the itemWidth option, if specified, items will be stretched to fill the container width.
  • 'fixed' - Item width will be defined by the content inside, or the itemWidth option, if specified.
  • integer - Number of items to display. If itemWidth is also specified, it will represent the maximum number of items to display.
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 'auto' or undefined, the theme will automatically be chosen based on the platform. If the theme for the specific platform is not present, it will revert to the Mobiscroll theme.

Supplied themes:
  • 'bootstrap' - Bootstrap themes
  • 'ios' - new iOS 7, 8, 9 theme
  • 'material' - Material theme (Android 5.x)
  • 'material-dark' - Material dark theme (Android 5.x)
  • 'mobiscroll' - Mobiscroll theme
  • 'mobiscroll-dark' - Mobiscroll Dark theme
  • 'windows' - Windows theme
  • 'windows-dark' - Windows theme (dark version)
It's possible to modify theme colors or create custom themes.
Make sure that the theme you set is included in the downloaded package.
threshold Number 10 Minimum horizontal movement in pixels before the scrolling starts.

Setting options runtime (changing options dynamically)

There are two ways to modify options after initalization

  1. 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 change
    angular
        .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>
  2. 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

  • event: Object - The event object has the following properties:
    • destinationX: horizontal destination position.
    • destinationY: vertical destination position.
    • direction: direction of the movement expressed in degree: 90 - up, 180 - left, 270 - down, 360 - right.
    • duration: animation duration in milliseconds.
    • originX: horizontal starting position.
    • originY: vertical starting position.
    • posX: the horizontal movement from the initial position.
    • posY: the vertical movement from the initial position.
    • transitionTiming : transition-timing function.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onAnimationEnd: function (event, inst) {
    }
};
onAnimationStart(event, inst) Gets fired when an autonomous scrolling/sliding is starts.

Parameters

  • event: Object - The event object has the following properties:
    • destinationX: horizontal destination position.
    • destinationY: vertical destination position.
    • direction: direction of the movement expressed in degree: 90 - up, 180 - left, 270 - down, 360 - right.
    • duration: animation duration in milliseconds.
    • originX: horizontal starting position.
    • originY: vertical starting position.
    • posX: the horizontal movement from the initial position.
    • posY: the vertical movement from the initial position.
    • transitionTiming : transition-timing function.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onAnimationStart: function (event, inst) {
    }
};
onGestureEnd(event, inst) Gets fired when the user ends the scrolling gesture.

Parameters

  • event: Object - The event object has the following properties:
    • direction: direction of the movement expressed in degree: 90 - up, 180 - left, 270 - down, 360 - right.
    • originX: horizontal starting position.
    • originY: vertical starting position.
    • posX: the horizontal movement from the initial position.
    • posY: the vertical movement from the initial position.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onGestureEnd: function (event, inst) {
    }
};
onGestureStart(event, inst) Gets fired when the user ends the scrolling(swiping) gesture.

Parameters

  • event: Object - The event object has the following properties:
    • direction: direction of the movement expressed in degree: 90 - up, 180 - left, 270 - down, 360 - right.
    • originX: horizontal starting position.
    • originY: vertical starting position.
    • posX: the horizontal movement from the initial position.
    • posY: the vertical movement from the initial position.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onGestureStart: function (event, inst) {
    }
};
onInit(event, inst) Triggered when the component is initialized.

Parameters

  • event: Object - The event object.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onInit: function (event, inst) {
    }
};
onItemTap(event, inst) Triggered when an item is tapped.

Parameters

  • event: Object - The event object has the following properties:
    • target: HTMLElement - The DOM element of the tapped item.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onItemTap: function (event, inst) {
    }
};
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

  • event: Object - The event object has the following properties:
    • target: Object - The DOM element containing the generated html.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onMarkupReady: function (event, inst) {
    }
};
onMove(event, inst) Gets fired when an autonomous scrolling/sliding ends.

Parameters

  • event: Object - The event object has the following properties:
    • destinationX: horizontal destination position.
    • destinationY: vertical destination position.
    • direction: direction of the movement expressed in degree: 90 - up, 180 - left, 270 - down, 360 - right.
    • duration: animation duration in milliseconds.
    • originX: horizontal starting position.
    • originY: vertical starting position.
    • posX: the horizontal movement from the initial position.
    • posY: the vertical movement from the initial position.
    • transitionTiming : transition-timing function.
  • inst: Object - The instance object of the scrollview.

Example

$scope.settings = {
    onMove: function (event, inst) {
    }
};

Methods

Name Description
getInst() Returns the object instance.

Returns: Object

  • The object instance.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.getInst();
navigate(item [, toggle ]) Scrolls the scrollview to the specified item.

Parameters

  • item: Object or String - The jQuery object or the id of the list item (id must be present in the item's data-id attribute).
  • toggle: Boolean - If true, it also toggles the selected state of the item and triggers the onItemTap event. If undefined, defaults to true in single select mode and to false in multiselect mode.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.navigate(1);
next([toggle]) Scrolls the scrollview to the next item.

Parameters

  • toggle (Optional): Boolean - If true, it also toggles the selected state of the item and triggers the onItemTap event. If undefined, defaults to true in single select mode and to false in multiselect mode.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.next();
option(options) Sets one or more options for the component.

Parameters

  • options: Object - A map of option-value pairs to set.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.option({
    display: 'bottom',
    lang: 'de' 
});
prev([toggle]) Scrolls the scrollview to the previous item.

Parameters

  • toggle (Optional): Boolean - If true, it also toggles the selected state of the item and triggers the onItemTap event. If undefined, defaults to true in single select mode and to false in multiselect mode.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.prev();
refresh() Recalculate dimensions needed for scrolling.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.refresh();
tap(el, handler) Attaches the handler function to the tap event of element el.

Parameters

  • el: Object - The element with tap event.
  • handler: Function - If the action was initiated with touch event, handler is called on touchend, otherwise on click.

Example

Methods can be called on an instance. For more details see calling methods
$scope.mobiscrollInstance.tap('#element', function () { alert("It's a tap!"); });

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:
  • Arabic: 'ar'
  • Bulgarian: 'bg'
  • Catalan: 'ca'
  • Czech: 'cs'
  • Chinese: 'zh'
  • Croatian: 'hr'
  • Danish: 'da'
  • Dutch: 'nl'
  • English: 'en' or 'en-US' or undefined
  • English (UK): 'en-UK' or 'en-GB'
  • Farsi: 'fa'
  • German: 'de'
  • Greek: 'el'
  • Spanish: 'es'
  • Finnish: 'fi'
  • French: 'fr'
  • Hebrew: 'he'
  • Hindi: 'hi'
  • Croatian: 'hr'
  • Hungarian: 'hu'
  • Italian: 'it'
  • Japanese: 'ja'
  • Korean: 'ko'
  • Lithuanian: 'lt'
  • Norwegian: 'no'
  • Polish: 'pl'
  • Portuguese (Brazilian): 'pt-BR'
  • Portuguese (European): 'pt-PT'
  • Romanian: 'ro'
  • Russian: 'ru'
  • Russian (UA): 'ru-UA'
  • Slovak: 'sk'
  • Serbian: 'sr'
  • Thai: 'th'
  • Swedish: 'sv'
  • Turkish: 'tr'
  • Ukrainian: 'ua'
  • Vietnamese: 'vi'
rtl Boolean false Right to left display.