html5 css3美化input滑塊拖動樣式代碼



97 387 130



特效描述:html5 css3美化 input 滑塊拖動樣式,html5 css3 input滑塊樣式

代碼結構

1. 引入CSS

<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">

2. 引入JS

<script src='js/stopExecutionOnTimeout.js?t=1'></script>

3. HTML代碼

<input type='range' id='r1' class='tip fill fill-replace' value='7' min='1' max='13' />
<input type='range' id='r2' class='tip fill' value='60' />
<input type='range' id='r3' class='tip' value='25' step='25' />
<input type='range' id='r4' class='fill' value='87' />
<script>
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);
</script>



用戶評論
大牛,別默默的看了,快登錄幫我點評一下吧!:)      登錄 | 注冊


熱門標簽: 拖動 拖拽 拖動插件 拖拽插件 圖片拖動 圖片拖拽
?
×
×

注冊

官方QQ群

掃描上面二維碼加微信群

官方QQ群

jQuery/js討論群
群號:642649996
Css3+Html5討論群
群號:322131262

加群請備注:從官網了解到

湖北30选5开奖结果走势图表