• JS放大镜效果~


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            *{
                margin:0;
                padding:0;
            }
            #box{
                375px;
                height:250px;
                border:1px red solid;
                float:left;
                position:relative;
                margin-left:50px;
                margin-top:50px;
            }
            #leftImg{
                375px;
                height:250px;
                display:block;
            }
            #drag{
                187.5px;
                height:125px;
                background:yellow;
                position:absolute;
                left:0;
                top:0;
                opacity:0.4;
                filter:Alpha(opacity=40);/*解决IE8以下!!!!*/
                cursor:move;
                display:none;
            }
            #rightImg{
                750px;
                height:500px;
            }
            #rightShow{
                float:left;
                375px;
                height:250px;
                border:1px blue solid;
                overflow:hidden;
                display:none;
                margin-top:50px;
            }
        </style>
    </head>
    <body>
        <div id="box">
            <img id="leftImg" src="1200.jpg" alt="">
            <div id="drag"></div>
        </div>
        <div id="rightShow">
            <img id="rightImg" src="1200.jpg" alt="">
        </div>
    </body>
    <script>
        var oBox = document.getElementById('box');
        var drag = document.getElementById('drag');
        var rightShow = document.getElementById('rightShow');
    
        oBox.onmousemove = function  () {
            var e = event ||window.event;
            drag.style.display='block';
            rightShow.style.display='block';
            var lefts = e.clientX - oBox.offsetLeft - drag.offsetWidth/2;
            var tops = e.clientY - oBox.offsetTop - drag.offsetHeight/2;
            var maxWidth = oBox.offsetWidth - drag.offsetWidth;
            var maxHeight = oBox.offsetHeight - drag.offsetHeight;
            if(lefts > maxWidth){
                lefts = maxWidth
            }
            if (tops > maxHeight) {
                tops = maxHeight;
            }
            if (lefts<0) {
                lefts = 0
            }
            if (tops < 0) {
                tops = 0
            }
            drag.style.left = lefts + 'px';
            drag.style.top = tops + 'px';
            var num = rightImg.offsetWidth / leftImg.offsetWidth;
            rightShow.scrollLeft = drag.offsetLeft * num;
            rightShow.scrollTop = drag.offsetTop * num;
        }
        oBox.onmouseout = function(){
            drag.style.display = 'none';
            rightShow.style.display = 'none';
        }
    </script>
    </html>

  • 相关阅读:
    其实那女子根本就不是在三楼死的
    ARX工程必须使用release模式编译
    解决64bit不能连接access的问题
    bootstrap例子
    bootstrap登录界面
    Bootstrap3.0入门学习系列教程
    CentOS(Linux)中解决MySQL乱码
    linux yum命令详解
    CentOS yum 安装 Apache + PHP + MySQL
    Centos下配置php环境
  • 原文地址:https://www.cnblogs.com/jakning/p/4242113.html
Copyright © 2020-2023  润新知