时间:2021-07-01 10:21:17 帮助过:25人阅读
先看看效果图:
由于这控件的滚动是使用div原生滚动方法,触摸屏使用时可以有惯性滚动效果,也实现了鼠标可以操作,不过没有实现惯性滚动效果。由于此控件主要是面向触摸屏的,所以嘛触摸屏完美就好了,我也懒的弄鼠标版的特效了。此控件已封装成jquery插件,没有边框,100%宽,使用很方便,比如套入弹窗后就是上图效果。
代码使用方法如下:
$("#scrollbox").EasyScrollBox({ fontSize: 32, fontFamily: '', color: '#000', lineHeight: 1.5, spaceRows: 2, value: '4', data: data1, textFiled: 'txt', valueFiled: 'id', onSelected: function (index, value) { $("#Text1").val(value); } });
使用弹窗完整的使用方法代码如下,效果就是上图的样子:
<!-- ui-dialog --> <div id="dialog" class="easyui-dialog" style="padding:20px 6px;width:80%;" data-options="inline:true,modal:true,closed:true,title:'设置数值'"> <div id="scrollbox"></div> <div class="dialog-button"> <a href="javascript:void(0)" class="easyui-linkbutton" style="width:100%;height:35px" onclick="$('#dialog').dialog('close')">确 定</a> </div> </div> <script type="text/javascript"> $(function () { //对象型数据 var data = []; for (var i = 0; i < 100; i++) { var m = {}; m.id = i; m.txt = "数据" + i; data.push(m); } $("#dialog").dialog(); // Link to open the dialog $("#dialog-link").click(function (event) { $("#dialog").dialog("open").dialog('center'); //重新赋值 $("#scrollbox").EasyScrollBox({ fontSize: 32, fontFamily: '', color: '#000', lineHeight: 1.5, spaceRows: 2, value: '4', data: data, textFiled: 'txt', valueFiled: 'id', onSelected: function (index, value) { $("#Text1").val(value.id); } }); event.preventDefault(); }); }); </script>
也可以这么用:
//字符串数据 var data1 = []; for (var i = 0; i < 100; i++) { data1.push(i); } $("#scrollbox").EasyScrollBox({ fontSize: 32, fontFamily: '', color: '#000', lineHeight: 1.5, spaceRows: 2, value: '4', data: data1, onSelected: function (index, value) { $("#Text1").val(value); } }); $("#dialog-link1").click(function (event) { $("#dialog").dialog("open").dialog('center'); event.preventDefault(); });
如果想要一点三维效果,直接加样式即可:
#cover_top_EasyScrollBox{ background: -ms-linear-gradient(top, #000000, #ccc); /* IE 10 */ background:-moz-linear-gradient(top,#000000,#ccc);/*火狐*/ background:-webkit-gradient(linear, 0% 0%, 0% 100%,from(#000000), to(#ccc));/*谷歌*/ background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000000), to(#ccc)); /* Safari 4-5, Chrome 1-9*/ background: -webkit-linear-gradient(top, #000000, #ccc); /*Safari5.1 Chrome 10+*/ background: -o-linear-gradient(top, #000000, #ccc); /*Opera 11.10+*/ } #cover_bottom_EasyScrollBox{ background: -ms-linear-gradient(top, #ccc, #000000); /* IE 10 */ background:-moz-linear-gradient(top,#ccc,#0000ff);/*火狐*/ background:-webkit-gradient(linear, 0% 0%, 0% 100%,from(#ccc), to(#000000));/*谷歌*/ background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ccc), to(#000000)); /* Safari 4-5, Chrome 1-9*/ background: -webkit-linear-gradient(top, #ccc, #000000); /*Safari5.1 Chrome 10+*/ background: -o-linear-gradient(top, #ccc, #000000); /*Opera 11.10+*/ }