简单基于SSM整合的java项目(2)前端功能

增加前端放大镜

项目的产品页面是这样的

在这里插入图片描述
当点击这个页面时会跳转到一个页面
在这里插入图片描述
这个传值是通过简单的html传值实现的

<img src="" width="350"/>
"""
<script src="vendor/jquery.min.js" type="text/javascript"></script>
<script>

    function getParam() {
        var url = location.search;
        var value = url.substring(7);
        $('img').attr('src',value);
    }
    getParam()
</script>

使用了jquery的方法 attr 这个方法 是选择页面上的img标签,向img的src属性里添加value这个值。location.search
是获取url路径?后面的值。

之后是实现放大镜功能,完整代码
 <style>
        .nav-pills {
            background-color: black;
        }
        *{
            padding: 0;
            margin: 0;
        }
        .box{

            margin: 100px;
            border: 1px solid #fff;
            position: relative;
        }
        .small{
            position: relative;
            width: 350px;
            height: 350px;
        }
        .mask{
            width: 125px;
            height: 125px;
            background: rgba(255, 255, 0, 0.4);
            position: absolute;
            left: 0;
            top: 0;
            display: none;
            cursor: move;
        }
        .big{
            width: 350px;
            height: 350px;
            border: 1px solid #fff;
            position: absolute;
            top: 0;
            left: 360px;
            overflow: hidden;
            display: none;
        }
    </style>
</head>
<script type="text/javascript">
    window.onload = function(){
        var box = document.getElementsByClassName("box")[0];
        var small = box.children[0];
        var big = box.children[1];
        var bigImg = big.children[0];
        var mask = small.children[1];


        small.onmouseenter = function(){
            big.style.display = "block";
            mask.style.display = "block";
        };
        small.onmouseleave = function(){
            big.style.display = "none";
            mask.style.display = "none";
        };

        small.onmousemove = function(event){
            event = event || window.event;
            var pagex = event.pageX || scroll().left + event.clientX;
            var pagey = event.pageY || scroll().top + event.clientY;

            //减去mask宽高的一半,让鼠标在mask的中间
            var x = pagex - box.offsetLeft - mask.offsetWidth/2;
            var y = pagey - box.offsetTop - mask.offsetHeight/2;

            //不让mask超出small
            if(x < 0){
                x=0;
            }
            if(x > small.offsetWidth - mask.offsetWidth){
                x = small.offsetWidth - mask.offsetWidth;
            }
            if(y < 0){
                y=0;
            }
            if(y > small.offsetHeight - mask.offsetHeight){
                y = small.offsetHeight - mask.offsetHeight;
            }

            mask.style.left = x + "px";
            mask.style.top = y + "px";


            var scale = bigImg.offsetWidth / small.offsetWidth;

            bigImg.style.marginLeft = -scale * x +"px";
            bigImg.style.marginTop = -scale * y +"px";
        }
    };
</script>
<body>
    <!--页头-->
    <ul class="nav nav-pills">
        <li role="presentation"><a href="">首页</a></li>
        <li role="presentation"><a href="">产品信息</a></li>
        <li role="presentation"><a href="">公司咨讯</a></li>
        <li role="presentation"><a href="">公司简介</a></li>

    </ul>
    <div class="box">
    <div class="small">
        <img src="" width="350"/>
        <div class="mask"></div>
    </div>
    <div class="big">
        <img src=""/>
    </div>
    </div>
    <script src="vendor/jquery.min.js" type="text/javascript"></script>

</body>
<script>

    function getParam() {
        var url = location.search;
        var value = url.substring(7);
        $('img').attr('src','../../'+value);
    }
    getParam()
</script>
最终效果

在这里插入图片描述

github地址:https://github.com/zhoushibo-111/SSMairuiqiwebsite
gitee地址:https://gitee.com/zhoushiwangchao/SSMairuiqiwebsite
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值