ionic实现带字的toggle滑动组件?

ionic实现带字的toggle滑动组件


元芳怎么了
浏览 1434回答 1
1回答

qq_花开花谢_0

前言&nbsp;由于项目中需要带字的toggle滑动组件,而ionic提供的是这样的:&nbsp;&nbsp;&nbsp;实际项目中需要这样子的:&nbsp;&nbsp;在网上找了下其他的实现,感觉没得类似的,也没发现合适的,于是自己试着定义了一个凑合着用。先上效果图&nbsp;&nbsp; &nbsp;&nbsp;看效果图边缘有模糊锯齿现象,可能是由于像素的影响,在android和ios手机上表现非常流畅。&nbsp;实现代码&nbsp;其实实现起来也很简单,主要是算好滑块的位置,滑动用的是css的transform. &nbsp;css用到的类如下:&nbsp; &nbsp; &nbsp;.switch_search{ &nbsp; &nbsp;position:relative;display:flex;width:120px;height:28px; &nbsp; &nbsp;margin-top:8px;border:solid 1px #fff;border-radius:16px; &nbsp;} &nbsp;.switch_search_tab{ &nbsp; &nbsp;flex:1;height:28px;width:60px; &nbsp; &nbsp;line-height:28px;color:#203C4B;z-index:12; &nbsp;} &nbsp;.white_search_tab{ &nbsp; &nbsp;color:#fff; &nbsp;} &nbsp;.switch_bg{ &nbsp; &nbsp;background:#fff;border-radius:16px;position:absolute; &nbsp; &nbsp;top:-1px;left:-1px;height:28px;width:60px; &nbsp;} &nbsp;.search_right{ &nbsp; &nbsp;transition: -webkit-transform,transform 0.6s ease; &nbsp; &nbsp; -webkit-transform: translate3d(60px, 0, 0); &nbsp; &nbsp;-moz-transform: translate3d(60px, 0, 0); &nbsp; &nbsp; transform:translate3d(60px, 0, 0); &nbsp;} &nbsp;.search_left{ &nbsp; &nbsp;transition: -webkit-transform,transform 0.6s ease; &nbsp; &nbsp; -webkit-transform: translate3d(0px, 0, 0); &nbsp; &nbsp;-moz-transform: translate3d(0px, 0, 0); &nbsp; &nbsp; transform:translate3d(0px, 0, 0); &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;页面上html代码:&nbsp; &nbsp; &nbsp;<div class="switch_search"> &nbsp; &nbsp;<div class="switch_search_tab" on-swipe-right="activeSlideSearch(1)" ng-click="activeSlideSearch(0)" ng-class="(slideIndexSearch==0 ||slideIndexSearch==-1) ? '' : 'white_search_tab'"> &nbsp; &nbsp; &nbsp;月 &nbsp; &nbsp;</div> &nbsp; &nbsp;<div class="switch_search_tab" on-swipe-left="activeSlideSearch(0)" ng-click="activeSlideSearch(1)" ng-class="(slideIndexSearch==1) ? '' : 'white_search_tab'"> &nbsp; &nbsp; &nbsp;日 &nbsp; &nbsp;</div> &nbsp; &nbsp;<div class="switch_bg" ng-class="(slideIndexSearch==0 ||slideIndexSearch==-1) ? 'search_left' :'search_right'"></div> &nbsp;</div> &nbsp; &nbsp; &nbsp; &nbsp;对应的Controller js代码如下:&nbsp; &nbsp; &nbsp;$scope.slideIndexSearch=-1; &nbsp; $scope.activeSlideSearch = function(index) { &nbsp; &nbsp;$scope.slideIndexSearch=index; &nbsp;}; &nbsp; &nbsp; &nbsp; &nbsp;如此,便可实现简单的带字的滑动的toggle组件。 &nbsp;&nbsp;以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
打开App,查看更多内容
随时随地看视频慕课网APP