javascript - Ionic sliding between tabs template -


i downloaded ionic tabs template. played around while , wondering how add sliding function can navigate between tabs. in case, want slide animations , smooth transition, not sudden tab switch.

i saw on ionic docs. has slide box feature.

    <ion-slide-box on-slide-changed="slidehaschanged($index)">        <ion-slide>            <div class="box blue"><h1>blue</h1></div>        </ion-slide>        <ion-slide>           <div class="box yellow"><h1>yellow</h1></div>        </ion-slide>        <ion-slide>              <div class="box pink"><h1>pink</h1></div>        </ion-slide>     </ion-slide-box> 

but using tabs template ionic

<ion-tabs>     <ion-tab>         <ion-nav-view>         </ion-nav-view>     </ion-tab> 

how able incorporate these together?

thank you!

can done on ionic tabs structure.

firstly, need add controller tab in app.js:

.state('tab', {     url: '/tab',     abstract: true,     controller: 'tabsctrl',     templateurl: 'views/base/tabs.html' }) 

then, need modify tabs.html on-swipe-left, on-swipe-right attr , classes: 'active-tab-{{ activetab }}"' ion-tabs , 'nav-tab-0' first ion-nav-view . last number have increase in next ion-nav-views.

so tabs.html should this:

<ion-tabs class="tabs-icon-only tabs-color-active-positive active-tab-{{ activetab }}" on-swipe-left="onswipeleft()" on-swipe-right="onswiperight()">  <ion-tab title="notifications" icon-off="ion-flag" icon-on="ion-flag" ui-sref="tab.notifications">     <ion-nav-view name="tab-notifications" class="nav-tab-0"></ion-nav-view> </ion-tab>  <ion-tab title="profile" icon-off="ion-person" icon-on="ion-person" ui-sref="tab.profile">     <ion-nav-view name="tab-profile" class="nav-tab-1"></ion-nav-view> </ion-tab>  <ion-tab title="home-map" icon-off="ion-map" icon-on="ion-map" ui-sref="tab.home_map">     <ion-nav-view name="tab-home-map" class="nav-tab-2"></ion-nav-view> </ion-tab>  <ion-tab title="home-list" icon-off="ion-ios-list" icon-on="ion-ios-list" ui-sref="tab.home_list">     <ion-nav-view name="tab-home-list" class="nav-tab-3"></ion-nav-view> </ion-tab>  <ion-tab title="create" icon-off="ion-plus-round" icon-on="ion-plus-round" ui-sref="tab.create_event">     <ion-nav-view name="tab-create-event" class="nav-tab-4"></ion-nav-view> </ion-tab> </ion-tabs> 

next step fill controller. here need have table of states names in order in nav. heres code:

    $scope.tablist = [         'tab.notifications',         'tab.profile',         'tab.home_map',         'tab.home_list',         'tab.create_event'     ];      $scope.onswipeleft = function() {         for(var i=0; < $scope.tablist.length; i++) {             if ($scope.tablist[i] == $state.current.name && != $scope.tablist.length){                 $state.go($scope.tablist[i+1]);                 break;             }         }     };      $scope.onswiperight = function() {         for(var i=0; < $scope.tablist.length; i++) {             if ($scope.tablist[i] == $state.current.name && != 0){                 $state.go($scope.tablist[i-1]);                 break;             }         }     };      $scope.$on('$ionicview.enter', function() {         for(var i=0; < $scope.tablist.length; i++) {             if ($scope.tablist[i] == $state.current.name){                 $scope.activetab = i;                 break;             }         }     }); 

last animation , hidding ion-nav-views, can in scss files :

.tab-content {     display: block;     opacity: 0;     @include transition-property('left, right');     @include transition-duration(.3s); }  $tabs-count: 5;  @for $i 0 through $tabs-count {     @for $j 0 through $tabs-count {         .active-tab-#{$i} {             @if $i == $j {                 .nav-tab-#{$j} {                     opacity: 1;                     left: 0 !important;                     right: 0 !important;                 }             }             @if $i > $j {                 .nav-tab-#{$j} {                     left: -100%;                     right: 100%;                 }             }             @if $i < $j {                 .nav-tab-#{$j} {                     left: 100%;                     right: -100%;                 }             }         }     } } 

so togather make works native tab app. hope helped, solutions works great me.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -