JavaScript
发布时间:2022-04-16 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ionic实现可滑动的tab选项卡切换效果,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
利用ionic的slide-box组件实现可滑动的tab,主要是监听tab点击以及slide页面滑动的事件,做相应的处理,用ng-repeat循环,优化、简略了代码,有需要的同学可以看看。
先来张效果图:
![ionic实现可滑动的tab选项卡切换效果 ionic实现可滑动的tab选项卡切换效果](https://files.jb51.cc/file_images/article/201608/2016827160600141.gif?201672716610)
用到的css代码:
{
border-bottom:solid 1px #F2F2F2;
padding:6px 0;
}
.tab_
SELEct
{
border-bottom:solid 1px #3E89F
5;
box-shadow:0 -3px 8px #C1D3F0 inset;
}
.arrow-top
{
position: absolute;
width: 0;
height: 0;
top:20px;
border: 6px solid #3E89F
5;
border-right-color:transparent;
border-left-color: transparent;
border-top-color: transparent;
}
.arrow-top:after
{
content:'';
position:absolute;
width: 0;
height: 0;
border: 12px solid #fff;
right: -12px;
bottom: -13px;
border-right-color:transparent;
border-left-color: transparent;
border-top-color: transparent;
}
页面上html代码:
View view-@R_
262_10283@e="滑动tab">
false">
:100%;">
:1;text-align: center;" class="tab_default" ng-repeat="d in tabNames" ng-click="activeSlide($inde
X)" ng-class="slec
Tindex==$index ? 'tab_
SELEct' : '' ">
{{D}}
{
{15+$index*33}}%" ng-show="slec
Tindex==$index">
X)" active-slide="slideIndex" does-conTinue="false" show-pager="false">
对应的controller.js代码:
Tindex
=0;
$scope.activeSlide=function(inde
X){//点击时候触发
$scope.slec
Tindex=index;
$ionicSlideBoxDelegate.slide(inde
X);
};
$scope.slideChanged=function(inde
X){//滑动时候触发
$scope.slec
Tindex=index;
};
$scope.pages=["templates/tab01.html","templates/tab02.html","templates/tab03.html"];
tab01.html、tab02.html、tab03.html这几个都是差不多的,贴一个tab01的:
:100%;text-align: center;padding-top:30px;">
page 01
:100%;"/>
tab的样式;
•滑动的时候是用的slide-box的一个函数,on-slide-changed,当slide页面发发生变化的时候,会向改函数传递一个变量index标识当前slide的索引 ;
•如果不想滚动只点击,可以去掉on-slide-changed的监听,也可以增加一个属性,disable-scroll="true",禁止slide page滚动;