<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>
            java語言

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

            時間:2025-02-21 02:21:56 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="http://cdn.attach.qdfuns.com/notes/pics/201702/08/162503mw0fawb5b02va22i.jpg" />

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

              </p>

              <p class="big">

              <img src="http://cdn.attach.qdfuns.com/notes/pics/201702/08/162503mw0fawb5b02va22i.jpg" />

              </p>

              </p>

              </body>

              <script type="text/javascript">

              var fdj = document.querySelector('.fdj') // 獲得最大的盒子

              var small = document.querySelector('.small'); //獲取小圖片盒子

              var big = document.querySelector('.big'); //獲取大圖片盒子

              var bigs = big.children[0] //大圖片

              var smalls = small.children[0] //小圖片

              var mask = small.children[1]; //遮罩

              //鼠標移入小圖片盒子

              small.onmouseover = function() {

              //鼠標移入圖片盒子將遮罩與大圖片顯示

              mask.style.display = 'block';

              big.style.display = ' block';

              };

              //鼠標移出小圖片盒子

              small.onmouseout = function() {

              //鼠標移出小圖片盒子將遮罩與大圖片隱藏

              mask.style.display = 'none';

              big.style.display = 'none';

              };

              var x=0;

              var y=0;

              //鼠標在小圖片上移動時

              small.onmousemove = function(ev) {

              var ev = event || window.event;

              //讓鼠標在遮罩正中

              //鼠標X坐標與Y坐標

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

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

              //將遮罩限制在小圖片盒子中

              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';

              //大圖與小圖的比例

              /*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實現小球的自由移動代碼08-26

            java實現gif動畫效果代碼參考07-23

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

            如何實現JavaScript的DIV塊來回滾動效果06-30

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

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

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

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

            Javascript到PHP加密通訊的簡單實現07-23

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看