可拖动的进度条和放大的图片

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>进度条</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css"/>
<script src="jquery/jQuery-2.2.0.min.js" type="text/javascript" charset="utf-8"></script>

</head>
<body>







<style type="text/css">
 #div1 {
  width: 600px;
  height: 20px;
  background: orange;
  position: relative;
  margin: 50px auto;
 }
 #div2 {
  width: 20px;
  height: 20px;
  background: green;
  position: absolute;
 }
 #div3 {
  width: 0;
  height: 0;
  margin: 20px auto;
 }
 #div3 img {
  width: 100%;
  height: 100%;
 }
 </style>
<div id="div1">
<div id="div2"></div>
</div>


<div id="div3">
<img src="">
</div>

<script type="text/javascript">
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var oDiv3 = document.getElementById('div3');
 
 
oDiv2.onmousedown = function(ev) { //鼠标按下的时候

  var oEvent = ev || event; //ev 成立时 oEvent = event,否则 oEvent = ev , 事件对象 兼容处理
  
  var disX = oEvent.clientX - oDiv2.offsetLeft; //鼠标当前相对于左面的距离
  
  document.onmousemove = function(ev) { //鼠标指针移动时
 
  var oEvent = ev || event;  //当前的事件对象  oDiv2
  
  var l = oEvent.clientX - disX;  //oEvent.clientX 表示 oDiv2相对于页面左侧的距离,l表示现在的大小
  
  if (l < 0) { //小于规定距离时
 
    l = 0; //初始化距离
   
  }else if (l > oDiv1.offsetWidth - oDiv2.offsetWidth) { //超出内容的时候
 
   l = oDiv1.offsetWidth - oDiv2.offsetWidth; //使用最大内容
  }
  
  oDiv2.style.left = l + 'px'; //l范围:[0,580] , 控制的滚动距离
  
  //document.title = l / 580; //范围:[0,1]
  
  var ratio = oDiv1.offsetWidth - oDiv2.offsetWidth; //总的大小
  
  var scale = l / ratio; //l表示现在的大小,scale增加的百分比
  
  var w = 600 * scale; //图片宽度
  var h = 370 * scale; //图片高度
  
  oDiv3.style.cssText = ';width:' + w + 'px;height:' + h +'px;'; //改变图片的值
  };
  document.onmouseup = function() {
 
  document.onmousemove = null;
  document.onmouseup = null;
  };
};
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值