您想问的可能是“jQuery实现放大镜效果”,以下是关于jQuery实现放大镜效果的相关信息:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>jQuery Image Zoom Demo</title>
<meta name="author" content="Jackson Huang">
<style>
.magnify { position: relative; }
.large, .small { width: 200px; height: 200px; }
.large { position: absolute; top: 0; left: 200px; overflow: hidden; display: none; }
.small img, .large img { width: 100%; height: 100%; }
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$(".small").hover(function() {
$(".large").fadeIn(100);
}, function() {
$(".large").fadeOut(100);
});
$(".small").mousemove(function(e) {
var mX = e.pageX - $(".small").offset().left - $(".large").width() / 2;
var mY = e.pageY - $(".small").offset().top - $(".large").height() / 2;
if (mX < 0) { mX = 0; }
if (mX > $(".small").width() - $(".large").width()) { mX = $(".small").width() - $(".large").width(); }
if (mY < 0) { mY = 0; }
if (mY > $(".small").height() - $(".large").height()) { mY = $(".small").height() - $(".large").height(); }
$(".large").css({
top: mY - $(".large").height() / 2 + "px",
left: mX - $(".large").width() / 2 + "px"
});
});
});
</script>
</head>
<body>
<div class="magnify">
<div class="large"></div>
<img class="small" src="./img/1.jpg" alt="">
</div>
</body>
</html>
通过上述代码,您可以实现一个基本的放大镜效果,当鼠标移动到小图上时,大图片会相应地放大显示。
希望这些信息对您有所帮助!如果您需要更详细的视频教程,建议您搜索相关的在线学习平台或教程网站。
领取专属 10元无门槛券
手把手带您无忧上云