赞
踩
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>滑动条</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
.box{
width: 400px;
height: 10px;
position: relative;
left: 0px;
top: 0px;
background-color: #ccc;
margin: 100px auto;
}
.box .box2{
width: 10px;
height: 20px;
background-color: #369;
position: absolute;
left: 0px;
top: -5px;
cursor: pointer;
/*cursor: default;*/
}
.box .cover{
width: 0px;
height: 10px;
position: absolute;
left: 0px;
top: 0px;
background-color: #369;
}
</style>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
window.onload=function(){
$("2box").onmousedown=function(event){
var evt=event||window.event;
var left1=evt.clientX-$("2box").offsetLeft;//长条方块的左边框的距离+鼠标距小蓝色方块的左边框的距离;
document.onmousemove=function(event){
var evt=event||window.event;
var location=evt.clientX-left1;
if(location<0)
{
location=0;
}
else if(location>390)
{
location=390;
}
$("2box").style.left=location+"px";
$("cover1").style.width=location+"px";
}
document.onmouseup=function(){
document.onmousemove=null;//取消注册的onmousemove事件;
}
}
}
</script>
</head>
<body>
<div class="box" id="1box">
<div class="box2" id="2box"></div>
<div class="cover" id="cover1"></div>
</div>
</body>
</html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。