zoukankan      html  css  js  c++  java
  • 购物查看放大

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style type="text/css">

    *{margin: 0;padding: 0;}

    #box{ 350px;height: 350px;border: 1px solid #ccc;cursor: pointer;position: relative;float: left;}

    #smallbox{ 180px;height: 180px;background: #ccc;opacity: 0.4;display: none;position: absolute;}

    #bigbox{ 400px;height: 400px;border: 1px solid #ddd;float: left;margin-left: 30px;display: none;position: relative;overflow: hidden;}

    img{position: absolute;}

    </style>

    </head>

    <body>

    <div id="box"><img src="img/min.jpg"/><div id="smallbox"></div></div>

    <div id="bigbox"><img src="img/max.jpg" id="img"/></div>

    </body>

    </html>

    <script type="text/javascript">

    var box=document.getElementById("box");

    var smallbox=document.getElementById("smallbox");

    var bigbox=document.getElementById("bigbox");

    var img=document.getElementById("img");

    box.onmouseenter=function(ev){

    var ev1=event||window.event;

    smallbox.style.display="block";

    bigbox.style.display="block";

    box.onmousemove=function(ev){

    var ev2=event||window.event;

    smallbox.style.left=ev2.clientX-box.offsetLeft-smallbox.clientWidth/2+"px";

    smallbox.style.top=ev2.clientY-box.offsetTop-smallbox.clientHeight/2+"px";

    if(smallbox.offsetLeft<0){

    smallbox.style.left=0;

    }

    if(smallbox.offsetLeft>(box.clientWidth-smallbox.offsetWidth)){

    smallbox.style.left=box.clientWidth-smallbox.offsetWidth+"px";

    }

    if(smallbox.offsetTop<0){

    smallbox.style.top=0;

    }

    if(smallbox.offsetTop>(box.clientHeight-smallbox.offsetHeight)){

    smallbox.style.top=box.clientHeight-smallbox.offsetHeight+"px";

    }

    var sl=box.clientWidth-smallbox.offsetWidth;

    var st=box.clientHeight-smallbox.offsetHeight;

    var bl=img.offsetWidth-bigbox.clientWidth;

    var bt=img.offsetHeight-bigbox.clientHeight;

    img.style.left=-(smallbox.offsetLeft/sl)*bl+"px";

    img.style.top=-(smallbox.offsetTop/st)*bt+"px";

    }

    }

    box.onmouseleave=function(){

    smallbox.style.display="none";

    bigbox.style.display="none";

    }

    </script>

  • 相关阅读:
    delphi vcl图像的二值化
    黑科技工具,推荐两款开源自动生成代码神器!
    推荐一款最强Python自动化神器!不用写一行代码!
    Java 展开或折叠PDF中的书签
    C# / VB.NET 获取PDF文档的数字签名信息
    滚蛋了
    MySQL 执行计划
    MySQL优化索引
    延时队列 DelayQueue
    【MongoDB】MongoDB 的存储过程
  • 原文地址:https://www.cnblogs.com/haodoubao/p/6080550.html
Copyright © 2011-2022 走看看