加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 正文

自定义样式的input[type=range]

发布时间:2018-10-08 20:07:00 所属栏目:创业 来源:站长网
导读:今天下午有人在群里提出个问题,能不能把自定义样式应用到HTML 5中的range元素上。晚上研究了一下,是可以实现上述的需求的。请用 Chrome 查看Demo。 代码如下: Copy to Clipboard 引用的内容:[www.veryhuo.com]!DOCTYPE html html head meta http-equiv

今天下午有人在群里提出个问题,能不能把自定义样式应用到HTML 5中的range元素上。晚上研究了一下,是可以实现上述的需求的。请用Chrome查看Demo。

代码如下:

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com] <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>自定義樣式的input[type=range]</title>
<style type="text/css">
#range {
width: 600px;
height: 10px;
background: rgba(60, 114, 230, .8);
border: 1px solid #333;
-webkit-border-radius: 5px;
-webkit-appearance: none !important;
}

#range::-webkit-slider-thumb{
width: 28px;
height: 28px;

background: -webkit-gradient(
linear,
left top,
left bottom,
from(#fff),
to(#ccc)
);

border: 1px solid #000;
-webkit-box-shadow: 0 0 6px #000;
-webkit-border-radius: 14px;
-webkit-appearance: none !important;
}

#result {
border: 2px solid #ccc;
width: 32px;
}
</style>
</head>
<body>
<input type='range' min='0' max='1000' value='0' id='range' />
<input type='text' id='result'/>
<script type='text/javascript'>
var result = document.getElementById('result');
document.getElementById('range').onchange = function() {
result.value = this.value;
}
</script>
</body>
</html>

代码中的”-webkit-appearance: none !important”很重要,要先把-webkit-appearance设置为none才能自定义样式。

作者:周明智
出处:http://www.ued163.com/?p=1286

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读