• jQuery 放大镜功能 简易放大镜


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>放大的图片</title>
    <script src="./js/jquery.min.js"></script>
    <style>
    *{margin:0;padding: 0;}
    .box_images{600px;margin: 0 100px; text-align: center;position:relative;}
    .box_images .box{auto;height:350px;overflow: hidden;max- 100%;max-height: 100%;display:flex;align-items: center;justify-content: center}
    .box_images .box img{auto;height:auto;max-height: 100%;max- 100%;}
    .fat{position: absolute; top: 0; left: 110%;400px;display: none;overflow: hidden;box-sizing: border-box; height: 350px;}
    .fatBox{position: relative;display: block;;100%;height:100%;}
    .fatBox img{position: absolute;top:0;left:0;object-fit: cover;}
    </style>
    </head>
    <body>
    <div class="box_images">
    <div class="box">
    <img src="images/mei.jpg" alt="">
    <!--<img src="images/beauty.jpg" alt="">-->
    </div>
    <div class="fat">
    <div class="fatBox">
    <img src="" alt="">
    </div>
    </div>
    </div>

    <script>

    function magnify(){
      let imagesBox = $(".box");
      let boxImg = $(".box img");
      let boxImgH = boxImg.height();
      let boxImgw = boxImg.width();
      let fat = $(".fat");
      let fatImg = $(".fat img");
      //定义一个变量来确定移动比例;
      let nums = 3;  

      //当前鼠标移入,移除

      boxImg.hover(function(){
        let $_this = $(this);
        fat.show()//显示放大区域
        let srcIs = $_this.attr("src");
        fatImg.attr("src", srcIs)
      },function(){
        fat.hide();//隐藏放大的区域
      });
      //当鼠标滑动的时候
      boxImg.on("mousemove",function(e){
      event = e || window.event;//兼容IE
      let offset_top = $(this).offset().top;
      let offset_left = $(this).offset().left;
      //动态设置 fatImg 的宽度
      fatImg.css({boxImgw*nums,height:boxImgH*nums,'object-fit': 'cover'});
      let x = e.pageX , y = e.pageY;
      let xx = x - offset_left;  
      let yy = y - offset_top;
      let xy = (x - offset_left) * nums;
      let yx = (y - offset_top) * nums;
      if(xy > fatImg.width() - fat.width() ){
        xy = fatImg.width() - fat.width()
      }
      if(yx > fatImg.height() - fat.height() ){
        yx = fatImg.height() - fat.height()
      }
      fatImg.css({
        top:-yx,
        left:-xy
      })
      })
    }
    magnify();
    </script>


    </body>
    </html>

    说明: 此代码属于个人笔记。不做他用勿喷。

  • 相关阅读:
    java:选择排序
    java:快速排序
    MYSQL 5.7版本修改密码
    多级代理下获取客户端真实IP
    map相关操作:map遍历,map转换为list
    【导航】微信开发者相关网址导航
    【java】微信开发后台官方后台配置篇
    HTML页面加载loading
    表单JS提交失效
    后台request获得所有参数(当你不知道它包含什么参数)
  • 原文地址:https://www.cnblogs.com/yangyang520/p/12175936.html
Copyright © 2020-2023  润新知