4

I'm using onsen-ui (v1.14), and I'm trying to swipe between tabs, like on facebook messenger, but I'm not able to make it work.

I've tried using the "setActiveTab" function with ons-gesture-detector, in several combinations, but none worked.

valepu
  • 3,136
  • 7
  • 36
  • 67

1 Answers1

1

Here's what I did (for a tool bar)

css

.activebtn .ng-scope{
color: blue;
}

html

<ons-template id="list.html">
    <ons-toolbar var="tb">
      <div class="center">
        <ons-toolbar-button class="tbbtn" id="btn_0" ng-click="abc.setActiveCarouselItemIndex(0)">ALL</ons-toolbar-button>
        <ons-toolbar-button class="tbbtn" id="btn_1" ng-click="abc.setActiveCarouselItemIndex(1)">PEOPLE</ons-toolbar-button>
        <ons-toolbar-button class="tbbtn" id="btn_2" ng-click="abc.setActiveCarouselItemIndex(2)"> TOPICS</ons-toolbar-button>
        <ons-toolbar-button class="tbbtn" id="btn_3" ng-click="abc.setActiveCarouselItemIndex(3)">ACCOUNTS</ons-toolbar-button>
        </div>
    </ons-toolbar>


    <ons-carousel style="width: 100%; height: 100%" auto-scroll var="abc" ng-controller="ListCtrl">
        <ons-carousel-item>
         a...
        </ons-carousel-item>
        <ons-carousel-item>
         b...
        </ons-carousel-item>
        <ons-carousel-item>
         c...
        </ons-carousel-item>
        <ons-carousel-item>
         d...
        </ons-carousel-item>
      </ons-carousel>
</ons-template>

js

    app.controller('ListCtrl', function($scope, $http) {

        $('#btn_0').addClass('activebtn');
        setTimeout(function(){
            abc.on('postchange', function(){
                $('.tbbtn ').removeClass('activebtn');
                $('#btn_' + abc.getActiveCarouselItemIndex()).addClass('activebtn');
            });
        }, 400);
    });
Will Bowman
  • 407
  • 9
  • 20