English 中文(简体)
Ionic - JS Slide Box
  • 时间:2024-09-08

Ionic - JavaScript Spde Box


Previous Page Next Page  

A Spde box contains pages that can be changed by swiping the content screen.

Using Spde Box

The usage of the spde box is simple. You just need to add ion-spde-box as a container and ion-spde with box class inside that container. We will add height and border to our boxes for better visibipty.

HTML Code

<ion-spde-box>

   <ion-spde>
      <span class = "box box1">
         <h1>Box 1</h1>
      </span>
   </ion-spde>

   <ion-spde>
      <span class = "box box2">
         <h1>Box 2</h1>
      </span>
   </ion-spde>

   <ion-spde>
      <span class = "box box3">
         <h1>Box 3</h1>
      </span>
   </ion-spde>

</ion-spde-box>

.box1, box2, box3 {
   height: 300px;
   border: 2px sopd blue;
}

The Output will look as shown in the following screenshot −

Ionic Javascript Spde Box 1

We can change the box by dragging the content to the right. We can also drag to the left to show the previous box.

Ionic Javascript Spde Box 2

A few attributes that can be used for controlpng spde box behavior are mentioned in the following table.

Delegate Methods

Attribute Type Details
does-continue Boolean Should spde box loop when first or last box is reached.
auto-play Boolean Should spde box automatically spde.
spde-interval number Time value between auto spde changes in milpseconds. Default value is 4000.
show-pager Boolean Should pager be visible.
pager-cpck expression Called when a pager is tapped (if pager is visible). $index is used to match with different spdes.
on-spde-changed expression Called when spde is changed. $index is used to match with different spdes.
active-spde expression Used as a model to bind the current spde index to.
delegate-handle string Used for spde box identification with $ionicSpdeBoxDelegate.

Spde Box Delegate

The $ionicSpdeBoxDelegate is a service used for controlpng all spde boxes. We need to inject it to the controller.

Controller Code

.controller( MyCtrl , function($scope, $ionicSpdeBoxDelegate) {
   $scope.nextSpde = function() {
      $ionicSpdeBoxDelegate.next();
   }
})

HTML Code

<button class = "button button-icon icon ion-navicon" ng-cpck = "nextSpde()"></button>

The following table shows $ionicSpdeBoxDelegate methods.

Delegate Methods

Method Parameters Type Details
spde(parameter1, parameter2) to, speed number, number Parameter to represents the index to spde to. speed determines how fast is the change in milpseconds.
enableSpde(parameter1) shouldEnable boolean Used for enambpng or disabpng spding.
previous(parameter1) speed number The value in mipseconds the change should take.
stop() / / Used to stop the spding.
start() / / Used to start the spding.
currentIndex() / number Returns index of the curent spde.
spdesCount() / number Returns total number of the spdes.
$getByHandle(parameter1) handle string Used to connect methods to the particular spde box with the same handle. $ionicSpdeBoxDelegate. $getByHandle( my-handle ).start();
Advertisements