因项目需要那种可以通过手势滑动来选择月份的效果,所以动手做了个,代码如下:
<style type="text/css"> .autoPlanBottomBox{ width: 100%; } .bottom-box-body{ background: #C9CDD3; position: relative; } .select-box-list{ margin: 0 auto; text-align:center; } .select-box-list li{ color: #898C90; font-size: 28px; line-height: 1.8em; } .select-box-list li.active{ color: #484A4C; } .scale-box{ position:absolute; overflow:hidden; width: 100%; text-align:center; background: #E0E3E6; z-index: 9999; } .scale-box .select-box-list{ transition-property: transform; transform-origin: 0px 0px 0px; transform: translate3d(0px, -50px, 0); } .scale-box li{ font-size:28px; line-height: 1.8em; color: #484A4C; transform: scale(1.2); } .rDialog-wrap{ padding:0; } </style> <template> <div class="rDialog autoPlanBottomBox" style="top: inherit;z-index: 10000; left: 0px; bottom: 0;display:none"><div class="rDialog-wrap"> <div class="bottom-box-header" style=" background: #EEEFF0;line-height: 50px;color: #fff;"><span class="cancelBottomBox" style="float:left;color: #1782FC;width:30px;padding: 5px 20px"><</span> <span class="confirmBottomBox" style="float:right;padding: 5px 20px;color: #1782FC;">确定</span><div class="clear" style=" clear: both; "></div> </div> <div class="bottom-box-body"> <div class="scale-box"> </div> <div class="wrapperBottom"> <ul class="select-box-list"> <li> </li> <li> </li> <li>请选择日期</li> <li data-date="1">每月1日</li> <li data-date="2">每月2日</li> <li data-date="3">每月3日</li> <li data-date="4">每月4日</li> <li data-date="5">每月5日</li> <li data-date="6">每月6日</li> <li data-date="7">每月7日</li> <li data-date="8">每月8日</li> <li data-date="9">每月9日</li> <li data-date="10">每月10日</li> <li data-date="11">每月11日</li> <li data-date="12">每月12日</li> <li data-date="13">每月13日</li> <li data-date="14">每月14日</li> <li data-date="15">每月15日</li> <li data-date="16">每月16日</li> <li data-date="17">每月17日</li> <li data-date="18">每月18日</li> <li data-date="19">每月19日</li> <li data-date="20">每月20日</li> <li data-date="21">每月21日</li> <li data-date="22">每月22日</li> <li data-date="23">每月23日</li> <li> </li> <li> </li> </ul> </div> </div> </div></div> <div class="rDialog-mask autoPlanBottomBox-mask" style="z-index: 9999;display:none"></div> </template> <script> import {iScroll} from '../libs/iscroll'; /** * options 参数 * cancel 取消回调 * success 成功回调 */ function BottomBox(options){ var self = this; self.settings = $.extend({initScrollIndex: 2}, options); $("body").off("click", ".cancelBottomBox").off("click", ".confirmBottomBox").on("click", ".cancelBottomBox", function(){ self.hide(); options.cancel && options.cancel(); }).on("click", ".confirmBottomBox", function(){ self.hide(); options.success && options.success(self.getValue()); }); }; BottomBox.prototype.show = function(){ // initScrollIndex 初始选定的索引 var self = this, initScrollIndex = this.settings.initScrollIndex; $(".autoPlanBottomBox,.autoPlanBottomBox-mask").show(); var wrapperEl = $(".wrapperBottom"); // 如果有传date参数,则选定对应的那天 if(this.settings.date){ initScrollIndex = wrapperEl.find("li[data-date='"+ this.settings.date +"']").index(); } $(".scale-box").append(wrapperEl.children().clone()); setTimeout(function(){ // UI初始化 var scaleBox = $(".scale-box .select-box-list"), scale = $(".select-box-list").eq(0).height()/$(".select-box-list").eq(1).height(); var liHeight = wrapperEl.find("li").eq(0).height(); self.scaleBoxHeight = liHeight * scale; wrapperEl.css("height", (liHeight * 5) + 'px'); $(".scale-box").css({"height": self.scaleBoxHeight + "px", top: (self.scaleBoxHeight * 2) + "px"}); wrapperEl.css("height", liHeight * 5); $(".autoPlanBottomBox,.autoPlanBottomBox-mask").show(); // 初始化iscroll self.bottomScroller = new iScroll(wrapperEl[0],{ linkWrapper: scaleBox[0], linkWrapperTop: -liHeight*2, hScroll: false, vScroll: true, hScrollbar: false, vScrollbar: false, snap: "li", onScrollEnd: function(){ self.translateY = Math.abs((this.y-liHeight*2) * scale); } }); self.bottomScroller.scrollToElement(wrapperEl.find("li").eq(initScrollIndex)[0], 200); }, 100); }; BottomBox.prototype.hide = function(){ $(".autoPlanBottomBox,.autoPlanBottomBox-mask").hide(); }; BottomBox.prototype.getValue = function(){ var index = parseInt(this.translateY / this.scaleBoxHeight, 10); return $(".wrapperBottom").find("li").eq(index).data("date"); }; export default { ready (){ }, data (){ return { } }, methods: { init: function(options){ this.bottomBoxObj = new BottomBox(options); }, show: function(){ this.bottomBoxObj.show(); }, hide: function(){ this.bottomBoxObj.hide(); }, getValue: function(){ return this.bottomBoxObj.getValue(); } } } </script>
相关推荐
点击切换开关,不支持滑动
支持点击切换开关,不支持触摸滑动
仿ios日期滑动(滚轮)选择器效果,平面化非立体滚轮效果
仿ios滑动控件,希望可以帮助到大家,有问题可以加群讨论.Android开发经验交流群 454430053
IOS豪华日期控件,支持滑动屏幕多选,支持日期限制
仿ios全屏滑动解锁控件,文章说明地址:http://blog.csdn.net/xuehaiwuya1212/article/details/74516442
滑动选择
PickerUI Android library to display a list of items for pick one with blur effect (if you wish). Support for Android 3.0 and up. It supports portrait and landscape mode, saving the state. ...
Android仿IosDialog控件
tabbar--上下滑动控件tabbar和导航栏隐藏
模仿IOS滑动控件,网上也有,这个我优化了UI,做的是日期选择,还带星期显示。可以直接使用
自定义控件之仿IOS适用于Android的滑动开关
类似 iOS 带弹簧效果的左右滑动控件,可作为 AbsListView 和 RecyclerView 的 item
iOS 自定义滑动分段选择Slider 非常养眼
iOS的滑动评分控件,支持动画、滑动、非整型评分。
但是在ios端,星期标签和“完成”按钮所在的div,会跟随日期div的滑动一定出现滑动效果。看起来就像是在闪烁一样。 我尝试了禁止橡皮筋效果,但是不能滑动了 我尝试了重写touch事件,但是依然解决不了。 请问,...
Android超炫自定义滑动开关控件,高仿IOS系统,珍藏版!
自定义封装滑动评分控件,支持整星、半星、根据分数显示; [https://git.oschina.net/ruishengDu/RSStarRating.git](https://git.oschina.net/ruishengDu/RSStarRating.git)
一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件。可以让用户很方便的只需要滑动数字既可以选择日期。Mobiscroll作为一款jQuery日期插件可以让用户自定义主题,完全通过...