星空网 > 软件开发 > 网页设计

4种input元素滑块UI样式

分享4种input元素滑块UI样式是一款使用CSS3来渲染样式,使用JavaScript来处理滑块的鼠标拖动事件。效果图如下:

4种input元素滑块UI样式

在线预览    源码下载

实现的代码。

js代码:

var range_els = document.querySelectorAll('input[type=range]'), n = range_els.length, style_el = document.createElement('style'), styles = [], track_sel = [    '::-moz-range-track',    '::-webkit-slider-runnable-track',    ' /deep/ #track'  ], thumb_sel = [    '::-webkit-slider-thumb',    ' /deep/ #thumb'  ], a = ':after', b = ':before', s = [    '',    '%',    '%'  ];document.body.appendChild(style_el);for (var i = 0; i < n; i++) {  if (window.CP.shouldStopExecution(1)) {    break;  }  styles.push('');  range_els[i].addEventListener('input', function () {    var idx = this.id.split('r')[1] - 1, base_sel = '.js #' + this.id, str = '', min = this.min || 0, max = this.max || 100, c_style, u, edge_w, val;    this.setAttribute('value', this.value);    if (this.classList.contains('tip')) {      str += base_sel + thumb_sel[0] + a + ',' + base_sel + thumb_sel[1] + a + '{content:"' + this.value + s[idx] + '"}';    }    if (this.classList.contains('fill')) {      if (idx == 0) {        c_style = getComputedStyle(this);        u = c_style.backgroundSize.split(' ')[0].split('px')[0];        edge_w = (c_style.width.split('px')[0] - u * (max - min)) / 2;        val = (this.value - min) * u + edge_w + 'px';      } else {        val = this.value + '%';      }      if (this.classList.contains('fill-replace')) {        str += base_sel + track_sel[0] + '{background-size:' + val + '}';      }      str += base_sel + track_sel[1] + a + ',' + base_sel + track_sel[2] + a + '{width:' + val + '}';    }    styles[idx] = str;    style_el.textContent = styles.join('');  }, false);}window.CP.exitedLoop(1);

via:http://www.w2bc.com/article/2015-12-22-four-input-ui




原标题:4种input元素滑块UI样式

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

敦煌网开店:https://www.goluckyvip.com/tag/30816.html
敦煌网开店流程:https://www.goluckyvip.com/tag/30817.html
敦煌网论坛:https://www.goluckyvip.com/tag/30818.html
敦煌网买家:https://www.goluckyvip.com/tag/30819.html
选品过程中:https://www.goluckyvip.com/tag/3082.html
敦煌网卖家:https://www.goluckyvip.com/tag/30820.html
品牌出海新机遇,玩转“新兴”与“王牌”主题沙龙成功举办!:https://www.kjdsnews.com/a/1836370.html
每月资讯 | CBD为您带来最新行业动态:https://www.kjdsnews.com/a/1836371.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流