放大镜效果

var box = $('nav_box1');
var smallBox = box.children[0];
var mask = $('mask');
var bigBox = $('big_box');
var bigImg = bigBox.children[0];
smallBox.onmouseover=function () {
  mask.style.display='block';
  bigBox.style.display='block';
  smallBox.onmousemove=function (event) {
      var event = event || window.event;
      //求鼠标的坐标
      var pointX =event.clientX -smallBox.offsetParent.offsetLeft-mask.offsetWidth*0.5;
      var pointY =event.clientY -smallBox.offsetParent.offsetTop-mask.offsetHeight*0.5;
      //边界检测
      if(pointX<0){
          pointX=0
      }else if (pointX>=smallBox.offsetParent.offsetWidth-mask.offsetWidth){
          pointX=smallBox.offsetParent.offsetWidth-mask.offsetWidth;
      }
      if(pointY<0){
          pointY=0
      }else if (pointY>=smallBox.offsetParent.offsetHeight-mask.offsetHeight){
          pointY=smallBox.offsetParent.offsetHeight-mask.offsetHeight;
      }
      //移动
      mask.style.left = pointX + 'px';
      mask.style.top = pointY + 'px';
      bigImg.style.left = -pointX/(smallBox.offsetParent.offsetWidth/bigBox.offsetParent.offsetWidth);
      bigImg.style.top = -pointY/(smallBox.offsetParent.offsetHeight/bigBox.offsetParent.offsetHeight) ;
  }
};

bigImg.style.left = -pointX/(smallBox.offsetParent.offsetWidth/bigBox.offsetParent.offsetWidth);
bigImg.style.top = -pointY/(smallBox.offsetParent.offsetHeight/bigBox.offsetParent.offsetHeight) ;这两句要加+‘px’
还要加上这个定位,图片才能移动
#big_box img{
position: absolute;
top: 0;
left: 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值