• jS放大镜效果


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo4.aspx.cs" Inherits="test.demo4" %>

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>放大镜</title>
    <meta name="keywords" content="" />
    <meta name="Description" content="" />
    <style type="text/css">
    body,div,img {padding:0;margin:0;}
    .con {256px;height:192px;float:left;}
    .con img {256px;height:192px;position:absolute;border:1px blue solid;}
    .dingwei {position:absolute;100px;height:100px;background-color:black;filter:alpha(opacity=20);opacity:0.2;cursor:move;display:none;}
    .big {float:left;400px;height:400px;margin:100px;overflow:hidden;}
    </style>
    </head>
    <body>
    <div class="con" id="father" style="position:relative;">
    <img src="img/2.jpg" alt="图片"/>
    <div id="aa" class="dingwei">&nbsp;</div>
    </div>

    <div class="big" id="bpic">
    <div class="inside"><img src="img/2.jpg" alt="图片"/></div>
    </div>
    <script type="text/javascript">
    var divs = document.getElementById("aa");
     var fa = document.getElementById("father");
    var maxWidth = maxHeight = S = 0;
      var big = document.getElementById("bpic");
     fa.onmouseover = function () {
     divs.style.display = "block";
     big.style.display = "block";
      S = divs.offsetHeight / 2;
    maxWidth = fa.clientWidth - divs.offsetWidth;
     maxHeight = fa.clientHeight - divs.offsetHeight; //物块的活动范围;
       }

      fa.onmousemove = function (e) {
     a = e || window.event;
      var sbX = a.clientX;
      var sbY = a.clientY;
    var num = big.clientWidth / divs.clientWidth;
      var lf = sbX - S; //鼠标的位置减去元素位置的一半的值就是元素的定位值;
    var tp = sbY - S;
     //tp =tp<0?0:tp>maxHeight?maxHeight:tp;
     //lf =lf<0?0:lf>maxWidth?maxWidth:lf;//判断物块的定位位置然后进行设置
     if (tp < 0) { tp = 0; }
    else {
     if (tp > maxHeight) { tp = maxHeight; }
      else { tp = sbY - S; }
     }
      //判断物块的位置进行设置
       if (lf < 0) { lf = 0; }

     else {
      if (lf > maxWidth) { lf = maxWidth; }

      else { lf = sbX - S; }
     }

      divs.style.left = lf + "px";
     divs.style.top = tp + "px";
    big.scrollLeft = num * lf;
    big.scrollTop = num * tp;
     }

     fa.onmouseout = function () {
    divs.style.display = "none";
      big.style.display = "none";

     }

    </script> 

    </body>
    </html>


     

  • 相关阅读:
    [CLR via C#]5.2 引用类型和值类型
    Yii easyWechat 开发的时候报错:cURL error 60: SSL certificate problem: unable to get local issuer certificat
    前端浏览器自动刷新神器:Browsersync
    phpStudy 切换版本后没有权限的问题
    最全的CSS浏览器兼容问题
    (转)详解JS位置、宽高属性之一:offset系列
    js 跨域问题
    移动端IOS 固定下方的输入框,点击输入框位置会变的修复
    ie8网页时调用特定的css文件
    Bootstrap如何禁止响应式布局 不适配
  • 原文地址:https://www.cnblogs.com/aukle/p/3214909.html
Copyright © 2020-2023  润新知