<div id="box" style="height: 200px;width: 16px;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;">
<div id="test" style="height: 60px;width: 16px;background-color:#555;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<script>
test.onmousedown = function(e){
e = e || event;
var that = this;
var disY = e.clientY - this.offsetTop;
document.onmousemove = function(e){
e = e || event;
var T = e.clientY - disY;
if(T < 0){T = 0;}
var TMax = parseInt(box.style.height) - that.offsetHeight;
if(T > TMax){T = TMax;}
that.style.top = T + 'px';
}
document.onmouseup = function(){
document.onmousemove = null;
//释放全局捕获
if(test.releaseCapture){test.releaseCapture();}
}
//IE8-浏览器阻止默认行为
if(test.setCapture){test.setCapture();}
//阻止默认行为
return false;
}
</script>
<div id="box1" style="height: 200px;width: 16px;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;">
<div id="test1" style="height: 60px;width: 16px;background-color:#555;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<div id="box2" style="height: 16px;width: 200px;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;">
<div id="test2" style="height: 16px;width: 60px;background-color:#D62929;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<script>
function scrollbar(obj,str){
obj.onmousedown = function(e){
e = e || event;
var that = this;
//x轴方向
if(str == 'x'){
var disX = e.clientX - this.offsetLeft;
//否则为y轴方向
}else{
var disY = e.clientY - this.offsetTop;
}
document.onmousemove = function(e){
e = e || event;
if(str == 'x'){
var L = e.clientX - disX;
if(L < 0){L = 0;}
var LMax = parseInt(obj.parentNode.style.width) - that.offsetWidth;
if(L > LMax){L = LMax;}
that.style.left = L + 'px';
}else{
var T = e.clientY - disY;
if(T < 0){T = 0;}
var TMax = parseInt(obj.parentNode.style.height) - that.offsetHeight;
if(T > TMax){T = TMax;}
that.style.top = T + 'px';
}
}
document.onmouseup = function(){
document.onmousemove = null;
//释放全局捕获
if(obj.releaseCapture){obj.releaseCapture();}
}
//IE8-浏览器阻止默认行为
if(obj.setCapture){obj.setCapture();}
//阻止默认行为
return false;
}
}
scrollbar(test1);
scrollbar(test2,'x')
</script>
<div id="box" style="height: 16px;width: 200px;display:inline-block;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;">
<div id="test" style="height: 16px;width: 60px;background-color:#D62929;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<span id="result">0</span>
<script>
function scrollbar(obj,str,max){
obj.onmousedown = function(e){
e = e || event;
var that = this;
//比例系数
var ratio;
//x轴方向
if(str == 'x'){
var disX = e.clientX - this.offsetLeft;
ratio = max/(this.parentNode.offsetWidth - this.offsetWidth);
//否则为y轴方向
}else{
var disY = e.clientY - this.offsetTop;
ratio =max/(this.parentNode.offsetHeight - this.offsetHeight);
}
document.onmousemove = function(e){
e = e || event;
if(str == 'x'){
var L = e.clientX - disX;
if(L < 0){L = 0;}
var LMax = parseInt(obj.parentNode.style.width) - that.offsetWidth;
if(L > LMax){L = LMax;}
that.style.left = L + 'px';
result.innerHTML = Math.round(ratio * L);
}else{
var T = e.clientY - disY;
if(T < 0){T = 0;}
var TMax = parseInt(obj.parentNode.style.height) - that.offsetHeight;
if(T > TMax){T = TMax;}
that.style.top = T + 'px';
result.innerHTML = Math.round(ratio * T);
}
}
document.onmouseup = function(){
document.onmousemove = null;
//释放全局捕获
if(obj.releaseCapture){obj.releaseCapture();}
}
//IE8-浏览器阻止默认行为
if(obj.setCapture){obj.setCapture();}
//阻止默认行为
return false;
}
}
scrollbar(test,'x',100);
</script>
<div id="box" style="height: 16px;width: 200px;display:inline-block;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;">
<div id="test" style="height: 16px;width: 60px;background-color:#D62929;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<span id="result" style="width: 1px;height: 50px;background-color:pink;display:inline-block;"></span>
<script>
function scrollbar(obj,str,max){
obj.onmousedown = function(e){
e = e || event;
var that = this;
//比例系数
var ratio;
//x轴方向
if(str == 'x'){
var disX = e.clientX - this.offsetLeft;
ratio = max/(this.parentNode.offsetWidth - this.offsetWidth);
//否则为y轴方向
}else{
var disY = e.clientY - this.offsetTop;
ratio =max/(this.parentNode.offsetHeight - this.offsetHeight);
}
document.onmousemove = function(e){
e = e || event;
if(str == 'x'){
var L = e.clientX - disX;
if(L < 0){L = 0;}
var LMax = parseInt(obj.parentNode.style.width) - that.offsetWidth;
if(L > LMax){L = LMax;}
that.style.left = L + 'px';
result.style.width = Math.round(ratio * L) + 'px';
}else{
var T = e.clientY - disY;
if(T < 0){T = 0;}
var TMax = parseInt(obj.parentNode.style.height) - that.offsetHeight;
if(T > TMax){T = TMax;}
that.style.top = T + 'px';
result.style.width = Math.round(ratio * T) + 'px';
}
}
document.onmouseup = function(){
document.onmousemove = null;
//释放全局捕获
if(obj.releaseCapture){obj.releaseCapture();}
}
//IE8-浏览器阻止默认行为
if(obj.setCapture){obj.setCapture();}
//阻止默认行为
return false;
}
}
scrollbar(test,'x',100);
</script>
<div id="box" style="height: 200px;width: 16px;display:inline-block;background-color:#F5F5F5;border-radius:10px;box-shadow:inset 0 0 6px rgba(0,0,0,0.3);position:relative;vertical-align:middle;">
<div id="test" style="height: 60px;width: 16px;background-color:#D62929;box-shadow:inset 0 0 6px rgba(0,0,0,.3);border-radius:10px;position:absolute;"></div>
</div>
<span id="result" style="width: 100px;height: 200px;background-color:pink;display:inline-block;line-height:30px;vertical-align:middle;position:relative;overflow:hidden;"><div id="resultIn" style="position:absolute;top:0;">测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br>测试文字<br></div></span>
<script>
function scrollbar(obj,str){
var max = result.offsetHeight - resultIn.offsetHeight;
obj.onmousedown = function(e){
e = e || event;
var that = this;
//比例系数
var ratio;
//x轴方向
if(str == 'x'){
var disX = e.clientX - this.offsetLeft;
ratio = max/(this.parentNode.offsetWidth - this.offsetWidth);
//否则为y轴方向
}else{
var disY = e.clientY - this.offsetTop;
ratio =max/(this.parentNode.offsetHeight - this.offsetHeight);
}
document.onmousemove = function(e){
e = e || event;
if(str == 'x'){
var L = e.clientX - disX;
if(L < 0){L = 0;}
var LMax = parseInt(obj.parentNode.style.width) - that.offsetWidth;
if(L > LMax){L = LMax;}
that.style.left = L + 'px';
resultIn.style.top = Math.round(ratio * L) + 'px';
}else{
var T = e.clientY - disY;
if(T < 0){T = 0;}
var TMax = parseInt(obj.parentNode.style.height) - that.offsetHeight;
if(T > TMax){T = TMax;}
that.style.top = T + 'px';
resultIn.style.top = Math.round(ratio * T) + 'px';
}
}
document.onmouseup = function(){
document.onmousemove = null;
//释放全局捕获
if(obj.releaseCapture){obj.releaseCapture();}
}
//IE8-浏览器阻止默认行为
if(obj.setCapture){obj.setCapture();}
//阻止默认行为
return false;
}
}
scrollbar(test,'y');
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有