<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. JavaScript簡單實現放大鏡效果代碼

    時間:2025-12-27 20:42:10 java語言

    JavaScript簡單實現放大鏡效果代碼

      導語:JavaScript簡單實現放大鏡效果代碼是有百分網小編給大家提供的,大家可以參考閱讀,更多詳情請關注應屆畢業生考試網。

      <html>

      <head>

      <meta charset="UTF-8">

      <title></title>

      <style type="text/css">

      * {

      margin: 0;

      padding: 0;

      }

      img{

      vertical-align: top;

      }

      .fdj {

      width: 350px;

      height: 350px;

      position: relative;

      margin: 100px auto;

      border: 1px solid gainsboro;

      }

      .small {

      position: relative;

      }

      .small img {

      width: 350px;

      }

      .mask {

      width: 100px;

      height: 100px;

      background: rgba(255, 255, 0, 0.4);

      position: absolute;

      left: 0;

      top: 0;

      cursor: move;

      display: none;

      }

      .big {

      position: absolute;

      top: 0;

      left: 360px;

      width: 500px;

      height: 500px;

      border: 1px solid gainsboro;

      overflow: hidden;

      display: none;

      }

      .big img{

      position: absolute;

      left: 0;

      top: 0;

      }

      </style>

      </head>

      <body>

      <p class="fdj">

      <p class="small">

      <img src="/pic/notes/pics/201702/08/162503mw0fawb5b02va22i.jpg" />

      <p class="mask"></p>

      </p>

      <p class="big">

      <img src="/pic/notes/pics/201702/08/162503mw0fawb5b02va22i.jpg" />

      </p>

      </p>

      </body>

      <script type="text/javascript">

      var fdj = document.querySelector('.fdj') /pic/p>

      var small = document.querySelector('.small'); /pic/p>

      var big = document.querySelector('.big'); /pic/p>

      var bigs = big.children[0] /pic/p>

      var smalls = small.children[0] /pic/p>

      var mask = small.children[1]; /pic/p>

      /pic/p>

      small.onmouseover = function() {

      /pic/p>

      mask.style.display = 'block';

      big.style.display = ' block';

      };

      /pic/p>

      small.onmouseout = function() {

      /pic/p>

      mask.style.display = 'none';

      big.style.display = 'none';

      };

      var x=0;

      var y=0;

      /pic/p>

      small.onmousemove = function(ev) {

      var ev = event || window.event;

      /pic/p>

      /pic/p>

      x = ev.clientX -this.offsetParent.offsetLeft- mask.offsetWidth / 2 ;

      y = ev.clientY -this.offsetParent.offsetTop- mask.offsetHeight / 2 ;

      /pic/p>

      if (x<0) {

      x=0;

      }else if(x>small.offsetWidth-mask.offsetWidth){

      x = small.offsetWidth-mask.offsetWidth;

      }

      if(y<0){

      y=0;

      }else if(y>small.offsetHeight-mask.offsetHeight){

      y= small.offsetHeight-mask.offsetHeight

      }

      mask.style.left = x + 'px';

      mask.style.top = y + 'px';

      /pic/p>

      /*var scalX = bigs.offsetWidth/small.offsetWidth;

      var scalY = bigs.offsetHeight/small.offsetHeight;*/

      var scalX = x/(small.offsetWidth-mask.offsetWidth);

      var scalY = y/(small.offsetHeight-mask.offsetHeight);

      bigs.style.left = -(x*scalX)+'px';

      bigs.style.top = -(y*scalY)+'px';

      };

      </script>

      </html>

    【JavaScript簡單實現放大鏡效果代碼】相關文章:

    javascript實現小球的自由移動代碼11-17

    java實現gif動畫效果代碼參考01-31

    Javascript實現全選并賦值給文本框代碼實例11-26

    如何實現JavaScript的DIV塊來回滾動效果12-26

    如何使用javascript實現瀑布流及效果加載12-03

    Java 隊列實現原理及簡單實現代碼10-13

    CSS實現自適應寬度的菜單按鈕效果代碼08-23

    CSS實現的中英文雙語菜單效果代碼02-19

    Javascript到PHP加密通訊的簡單實現03-15

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人