ustbhuangyi / picker Goto Github PK
View Code? Open in Web Editor NEW[警告]该库作者不再维护,picker 的维护移交至 cube-ui
Home Page: https://github.com/didi/cube-ui
[警告]该库作者不再维护,picker 的维护移交至 cube-ui
Home Page: https://github.com/didi/cube-ui
比如一个地区选择,应该是先选定是北京还是上海,然后再选择是哪个区,现在把所有二级项目都显示出来了,不合理啊
在安卓手机webview上,选择‘’项目‘’后点击‘’确定’’按钮 不会触发 picker.select 或者 picker.change 或者 picker.valuechange方法
城市联动选择的时候,在省选择停止的一瞬间,点击确定按钮,这个时候接获取到的第2,3列会不正确。偶然发现的。不过滑动效果确实挺好的。
能否给个参考事例,不知道点击确定的方法是如何调用的。
保存的是name,或value的值,怎么通过这个值在页面加载的时候,默认选中该值对应的城市
异常导致数据无法滚动,数字变形
Cannot assign to read only property '__esModule' of #<Object>
In some older browsers (<= Android 4).
css代码我做了优化,添加了从底部弹出的动画效果(源代码有重复无用的):
//UIPickerView 筛选器组件scss源码
@function h($height,$vh:rem) {
@return $height/20 +$vh; //常数20是根据当前引入的normalize.css 里的 font: 20px / 1.5
}
.picker {
display: none;
position: fixed;
top: 0;
z-index: 100;
width: 100%;
height: 100%;
overflow: hidden;
text-align: center;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
.picker-mask {
position: absolute;
z-index: 500;
width: 100%;
height: 100%;
transition: all .5s;
-webkit-transition: all .5s;
background: transparent;
opacity: 0;
&.show {
background: rgba(0, 0, 0, 0.6);
opacity: 1;
}
}
.picker-panel {
position: absolute;
z-index: 600;
bottom: -100%;
width: 100%;
background: #fff;
transition: all .6s;
-webkit-transition: all 0.6s;
&.show {
bottom:0;
transform: translateY(0);
-webkit-transform: translateY(0);
}
.picker-choose {
position: relative;
height: h(45);
color: #878787;
font-size: h(14);
background-color: #f8f8f8;
&::after {
position: absolute;
content: '';
width: 100%;
height: 1px;
left: 0;
bottom: 0;
background-color: #ccc;
transform: scaleY(.5);
transform-origin: bottom left;
}
.picker-title {
line-height: h(50);
font-size: h(19);
text-align: center;
color: #333;
display: none;
}
.cancel {
position: absolute;
padding: h(10);
font-size: h(17);
}
.confirm {
position: absolute;
padding: h(10);
font-size: h(17);
right: 0;
color: #2D72F1;
}
.cancel {
left: 0;
color: #2D72F1;
}
}
.picker-content {
position: relative;
.mask-bottom {
position: absolute;
z-index: 10;
width: 100%;
height: h(68);
pointer-events: none;
transform: translateZ(0);
-webkit-transform: translateZ(0);
}
.mask-top {
position: absolute;
z-index: 10;
width: 100%;
height: h(68);
pointer-events: none;
transform: translateZ(0);
-webkit-transform: translateZ(0);
top: 0;
background: -webkit-gradient(linear, left bottom, left top, from(hsla(0, 0%, 100%, 0.4)), to(hsla(0, 0%, 100%, 0.8)));
background: -o-linear-gradient(bottom, hsla(0, 0%, 100%, 0.4), hsla(0, 0%, 100%, 0.8));
&:after {
content: " ";
display: block;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
border-top: 1px solid #ccc;
-webkit-transform-origin: left bottom;
transform-origin: left bottom;
}
}
.mask-bottom {
bottom: 0;
background: -webkit-gradient(linear, left top, left bottom, from(hsla(0, 0%, 100%, 0.4)), to(hsla(0, 0%, 100%, 0.8)));
background: -o-linear-gradient(top, hsla(0, 0%, 100%, 0.4), hsla(0, 0%, 100%, 0.8));
&:before {
content: " ";
display: block;
position: absolute;
left: 0;
width: 100%;
top: 0;
border-top: 1px solid #ccc;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
}
}
.wheel-wrapper {
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
padding: 0 h(10);
.wheel {
-ms-flex: 1 1 1 e-9px;
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
-webkit-flex-basis: 1 e-9px;
flex-basis: 1 e-9px;
width: 1%;
height: h(172);
overflow: hidden;
font-size: h(21);
.wheel-scroll {
margin-top: h(68);
line-height: h(36);
.wheel-item {
height: h(36);
overflow: hidden;
white-space: nowrap;
color: #333;
}
}
}
}
}
.picker-footer {
height: h(20);
}
}
希望加入三元运算
例: <input type="text" id="job" readonly>)
// JS 获取方法
// var job = [{text: '国家公务员', value: 1}, {text: '编辑策划', value: 2}, {text: '专业技术', value: 3}, {text: '公司职员', value: 4}, {text: '企业管理', value: 5}, {text: '服务人员', value: 6}, {text: '现役军人', value: 7}, {text: '在读学生', value: 8}, {text: '自由职业', value: 9}, {text: '其他', value: 10}];
//
// var picker0El = document.getElementById('job');
// var tag =picker0El.tagName.toLowerCase();
// var picker0 = new Picker({data: [job]});
// picker0.on('picker.select', function (selectedVal, selectedIndex) {
// //判断当前ID元素的tagName,写入对应数据;
// tag=='input'? picker0El.setAttribute("value",job[selectedIndex[0]].text): nameEl.innerText = job[selectedIndex[0]].text;
// });
//
// picker0El.addEventListener('click', function () {
// picker0.show();//显示UIPickerView 筛选器组件
// });
// JQ 获取方法
$('#job').on('click', function () {
const $this = $(this);
const $tag=$this.prop('tagName').toLowerCase();
const job = [{text: '国家公务员', value: 1}, {text: '编辑策划', value: 2}, {text: '专业技术', value: 3}, {text: '公司职员', value: 4}, {text: '企业管理', value: 5}, {text: '服务人员', value: 6}, {text: '现役军人', value: 7}, {text: '在读学生', value: 8}, {text: '自由职业', value: 9}, {text: '其他', value: 10}];
const picker0 = new Picker({data: [job]});
picker0.show();
picker0.on('picker.select', function (selectedVal, selectedIndex) {
$tag=='input'?$this.val(job[selectedIndex[0]].text): $this.text(job[selectedIndex[0]].text);
});
})
强烈建议:城市联动选择器的调用方法: PickerCity(id);
就是把亲的 "..\picker-master\docs\city\index.js" 用一个函数封装起来,然后调用。
----------------------------------------------------------------
function PickerCity(id) {
var idName = id == undefined ? 'city' : id;
var nameEl = document.getElementById(idName);
var tag =nameEl.tagName.toLowerCase();
……
picker.on('picker.select', function (selectedVal, selectedIndex) {
var text1 = first[selectedIndex[0]].text;
var text2 = second[selectedIndex[1]].text;
var text3 = third[selectedIndex[2]] ? third[selectedIndex[2]].text : '';
/*判断当前ID元素的tagName,写入对应数据;*/
tag=='input'? nameEl.setAttribute("value",text1 + ' ' + text2 + ' ' + text3): nameEl.innerText = text1 + ' ' + text2 + ' ' + text3;
});
……
}
----------------------------------------------------------------
1. PickerCity() 是调用城市筛选器的函数,默认调用的元素ID为“city”,可以不带ID。
例: <input type="text" id="city" readonly>
PickerCity();
2. 如果默认ID不是“city”,需带参元素ID。
例: <input type="text" id="currentCity" readonly>
PickerCity('currentCity');
请问一下,作者什么时候可以把地址联动加上? RT,作者可以加入到后续开发计划当中...或者提供相应接口
强烈建议加入普通的日期选择,这么好的动画效果,没有最常见的日期选择岂不是太可惜了!!强烈建议!!不然还要自己封装年月日的数据往里面填
RT。
墙裂需求~
refill的时候会报can not read undefine[0],可能哪里没有初始化,麻烦作者看看,不知道你还在维护这个项目吗?
A、B两列,第一列变了,第二列的数据会有变动,这个能实现吗?
如题picker.change偶尔会拿不到回调
ERROR in .//.0.23.1@css-loader!.//.1.6.1@stylus-loader!./src/picker/picker.styl
Module build failed: TypeError: E:\Project\happyvalleyApp-pay\plugins\picker\src\picker\picker.styl:111:1
107| .border-1px
108| &::after, &::before
109| -webkit-transform: scaleY(.5)
110| transform: scaleY(.5)
111|
--------^
112|
Path must be a string. Received undefined
window 10/ node v6.9.1/ npm v3.10.5
IE 模式下,会提示 picker.min.js 里面的 26行 e: {default:e}; 错误,缺少标识符、字符串或数字。。应该是JSON 最后的符号,最后一个符号不应该加”,“ 引起的,只是不知道在哪个地方。demo 里面也是这样,麻烦处理一下
初始化之后没有wheels 所以使用scrollColum报错,cancel的时候有wheels属性但是wheelTo貌似没起到作用
业务场景:
在一些页面当中,可能存在多个需要用到picker
组件的地方。如果每次都new
一个新的picker
,会在DOM
当中新插入一个picker
。可以只使用一个picker
来满足多个需要选择的业务场景
可添加2个方法:
changeTitle
用以改变title
的显示,reConstruct
区别于refill
方法,可以提供3列选项的替换.
您好 请问如何整合到vue框架中呢
你好,目前这个插件还维护吗
请问option的滚动算法是在wheel.js那个文件里面吗?
源码中picker是append到body上,在单页应用中应用,会导致picker脱离在view外面,不手动关闭会一直留在页面
比如一个地区选择,应该是先选定是北京还是上海,然后再选择是哪个区,现在把所有二级项目都显示出来了,不合理啊
在./src/picker/picker.js
文件第107行加入滚动的监听
this.wheels[index].on('scroll', () => {
console.log(3333);
});
发现并没有被监听,反而是scrolStart这些就可以,这是为什么呢
信了淘宝的忽悠,viewport自动缩放了,不是大多数那种设置为1.0了..
现在搜索到的picker都是1.0倍的,并且我找到的你的picker是最流畅的(同样流畅度的picker不超过两个)..
好不好改.
需要在滚动的时候来触发一些事件,停止滚动了也一样,不知道是否有暴露出相应方法,或者在源码何处望指教
当页面长度超过一屏,页面有滚动条时,当向下滑动滚动条,然后再点击插件选择,插件完全不能上下滑动进行选择,在苹果5,苹果6s下,chrome,safari,uc,安卓的 uc, 手机百度,浏览器测试都有这个问题。提醒大家,此bug不解决,不要使用此插件
不然我自己撸了!
在用黄老师的地区选择时发现的,比如selectedIndex传个[6,2,2],初始化选中只会选中前两项,而且第二项是永远是北京的地区,是不是bug~
我思考了下,如果仅仅是A选择器,省市县之间的数据切换是没有问题的,在A选择器选择完之后,更新选择器B的数据,bug就出现,我表示做的好蛋疼,楼主好像是慕课网vue老师以及better-scroll插件的创始人
您好 请问如何修改样式呢 想把字体改小点,我修改了picker.styl,但并没起作用
原因:方便调试。
直接报Cannot read property '0' of undefined。还有因为用的angular,很难和你另外那个VUE picker插件结合。
代码如下:
ngOnInit(){
//界面初始化
this.picker=new Picker({
data: [[{text:1,value:1}]],
title: "选择阈值",
selectedIndex: [0]
})
}
selectPicker(i){
//点击后的回调
let newData=[[{text:2,value:12}]]
this.picker.refill(newData);
this.picker.show();
console.log(this.picker.data)
}
RT。
每当选项的selectIndex改变的时候,派发一个valuechange事件,以便作值改变的操作。
如题,有没有预设这个方法?也就是每个选项可以单独设置一个title?
如果初始传入selectedIndex值,如[6,2,2],之后关闭picker,重新根据这个值打开,重新修改第二列的数据时发现第三列没有对应的数据显示了这是不是又是个bug
选完第二级出现第三级,有时候再选第二级的时候 第三级没变动.,不知道大家有没有遇到过
picker在点击一次选中三列数据过后,html能正常显示选中的文本,在点击第二次只滚动一列,然后确定,只有选中的值变化!其余二列都是第一行!在安卓手机是这样!!..... 苹果跟浏览器正常
我看了您的md说明,没有找到怎么做两级城市联动,怎么修改样式文件
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.