标签:box style container 鼠标 放到 top 50 js bigger
动图效果:
代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } .container, img, .bigger { width: 200px; height: 200px; } .container { display: inline-block; position: relative; background: url(images/1.png) center; background-size: contain; } img { position: absolute; top: 0; left: 0; } .box { width: 100px; height: 100px; background-color: #ffff7f; opacity: 0.7; position: absolute; } .bigger { position: relative; display: inline-block; overflow: hidden; } .biggerImg { position: absolute; transform: scale(2); transform-origin: top left; } </style> </head> <body> <div class="container"> <div class="box" style="top: 0px;left: 0px;"></div> </div> <div class="bigger"> <img class="biggerImg" src="./images/1.png" style="display: none;" /> </div> </body> <script type="text/javascript"> var container = document.querySelector(".container"); var box = document.querySelector(".box"); var bigger = document.querySelector(".biggerImg"); var width = box.parentNode.offsetWidth; var height = box.parentNode.offsetHeight; container.addEventListener("mousedown", function() { bigger.style.display = "block"; container.addEventListener("mousemove", mouseMove); container.addEventListener("mouseup", function() { bigger.style.display = "none"; container.removeEventListener("mousemove", mouseMove); }) }); function mouseMove(e) { if (e.clientY - 50 < 0) { box.style.top = 0; bigger.style.top = 0; } else if (e.clientY - 50 > 100) { box.style.top = 100; bigger.style.top = 100; } else { box.style.top = e.clientY - 50 + "px"; bigger.style.top = -2 * (e.clientY - 50) + "px"; } if (e.clientX - 50 < 0) { box.style.left = 0; bigger.style.left = 0; } else if (e.clientX - 50 > 100) { box.style.left = 100; bigger.style.left = 100; } else { box.style.left = e.clientX - 50 + "px"; bigger.style.left = -2 * (e.clientX - 50) + "px"; } } </script> </html>
标签:box,style,container,鼠标,放到,top,50,js,bigger 来源: https://www.cnblogs.com/sunshine233/p/15628599.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。