jquery放大镜

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>放大镜</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        list-style: none;
    }
    .box1{
        width: 300px;
        height: 300px;
        margin: 50px 20px 50px 50px;
        float: left;
        position: relative;
    }
    .box1 img{
        width: 100%;
        height: 100%;
    }
    .box2{
        position: relative;
        width: 300px;
        height: 300px;
        overflow: hidden;
        float: left;
        margin-top: 50px;
        display: none;
    }
    .box2 img{
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
    }
    .pointer{
        position: absolute;
        top: 0;
        left: 0;
        width: 100px;
        height: 100px;
        background-image: url("https://img-tmdetail.alicdn.com/tps/i4/T12pdtXaldXXXXXXXX-2-2.png");
        cursor: move;
        display: none;
    }
    .opcity{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 999;
    }
</style>
<body>
<div class="box1">
    <div class="opcity"></div>
    <img src="https://img.alicdn.com/imgextra/i2/3015214310/TB2utMYp5MnBKNjSZFoXXbOSFXa_!!3015214310.jpg_430x430q90.jpg" alt="">
    <div class="pointer"></div>
</div>
<div class="box2">
    <img src="https://img.alicdn.com/imgextra/i2/3015214310/TB2utMYp5MnBKNjSZFoXXbOSFXa_!!3015214310.jpg_430x430q90.jpg" alt="">
</div>
</body>
</html>
<script>
    $(".box1").mouseover(function () {
        $(".pointer").show();
        $(".box2").show();
    });
    $(".box1").mousemove(function (e) {
        let wx=e.offsetX-50,wy=e.offsetY-50;
        let maxwidth=$(".box1").width()-$(".pointer").width(),maxheight=$(".box1").height()-$(".pointer").height();
        if (wx>=maxwidth){
            wx=maxwidth
        }
        if (wx<0){
            wx=0
        }
        if (wy>=maxheight){
            wy=maxheight
        }
        if (wy<0){
            wy=0
        }
        $(".pointer").css({"left":wx+"px","top":wy+"px"});
        $(".box2 img").css({"width":"900px","height":"900px","left":-wx*3+"px","top":-wy*3+"px"})
    })
    $(".box1").mouseout(function () {
        $(".pointer").hide();
        $(".box2").hide();
    })
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值