前端JS電商放大鏡效果

來源:互聯網
上載者:User

標籤:meta   rip   function   top   style   電商   javascrip   jpg   har   

前端JS電商放大鏡效果:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>26-電商放大鏡</title>    <style type="text/css">            *{        padding: 0;        margin: 0;    }    #left{      padding: 0;    margin: 0;        width: 400px;        height: 400px;        border: 2px solid blue;        background: url(http://chuantu.biz/t6/17/1503469475x2063891122.jpg) no-repeat;        float: left;        cursor: crosshair;        position: relative;    box-sizing: border-box;    }    #box{        width: 200px;        height: 200px;        background: white;        opacity: 0.6;        position: absolute;        top: 0;        left: 0;        display: none;    box-sizing: border-box;    }    #cover{        width: 400px;        height: 400px;        background: red;        position: absolute;        left: 0;        top: 0;        opacity: 0;    box-sizing: border-box;    }    #right{        width: 400px;        height: 400px;        border: 2px solid black;        overflow: hidden;        position: relative;        display: none;    box-sizing: border-box;    }    #rpic{        position: absolute;    }    </style>    <script type="text/javascript">            window.onload = function(){        var left = document.getElementById("left");        var right = document.getElementById("right");        var rpic = document.getElementById("rpic");        var box = document.getElementById("box");        var cover = document.getElementById("cover");        // 給左側加滑鼠移動事件        cover.onmousemove = function(){            //獲得事件對象            var ev = window.event;            var mouse_left = ev.offsetX || ev.layerX;            var mouse_top = ev.offsetY || ev.layerY;            // document.title = mouse_left + ‘|‘ +  mouse_top;            //計算色塊的位置            var box_left = mouse_left - 100;            var box_top = mouse_top - 100;            // 判斷是否超出            if (box_left < 0) {                box_left = 0;            }            if (box_left > 200) {                box_left = 200;            }            if (box_top < 0) {                box_top = 0;            }            if (box_top > 200) {                box_top = 200;            }            // 讓色塊移動            box.style.left = box_left + ‘px‘;            box.style.top = box_top + ‘px‘;            //計算右側圖片位置            var rpic_left = box_left*-2;            var rpic_top = box_top*-2;            // 讓右側移動            rpic.style.left = rpic_left + ‘px‘;            rpic.style.top = rpic_top + ‘px‘;        }            //給左側加滑鼠移入事件            cover.onmouseover = function(){                // 讓左側色塊和右側隱藏                box.style.display = ‘block‘;                right.style.display = ‘block‘;            }            // 給左側加滑鼠移出事件            cover.onmouseout = function(){                // 讓左側色塊和右側隱藏                box.style.display = ‘none‘;                right.style.display = ‘none‘;            }    }    </script></head><body>    <div id="left">        <div id="box"></div>        <div id="cover"></div>    </div>    <div id="right">        <img src="http://chuantu.biz/t6/17/1503469419x2063891122.jpg" id="rpic">    </div></body></html>

 

前端JS電商放大鏡效果

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.