下面是html完整页面,直接复制运行即可才好看效果:
<!DOCTYPE html>
<html lang="zh" phone="1">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>滑动条</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<meta name="theme-color" content="#09924b">
<meta name="description" content="">
<style>
input[type="range"] {
-webkit-appearance: none;
background-color: #bdc3c7;
width: 300px;
height: 5px;
border-radius: 5px;
margin: 0 auto;
outline: 0;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
background-color: #49a9ee;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid white;
cursor: pointer;
transition: 0.3s ease-in-out;
}
input[type="range"]::-webkit-slider-thumb:hover {
background-color: white;
border: 2px solid #49a9ee;
}
input[type="range"]::-webkit-slider-thumb:active {
transform: scale(1.6);
}
</style>
</head>
<body>
<div>
<span class="value"></span>
<input type="range" min="0" max="100" step="1" value="10"></div>
</body>
<script type="text/javascript">
var elem = document.querySelector('input[type="range"]');
var target = document.querySelector('.value');
target.innerHTML = elem.value;
var rangeValue = function(){
var newValue = elem.value;
target.innerHTML = newValue;
}
elem.addEventListener("input", rangeValue);
</script>
</html>