jQuery鼠标悬停图片放大是一种常见的网页交互效果,通过监听鼠标悬停事件(mouseenter
和 mouseleave
),在鼠标悬停时放大图片,鼠标离开时恢复原状。
以下是一个简单的jQuery鼠标悬停图片放大的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Hover Zoom</title>
<style>
.image-container {
position: relative;
display: inline-block;
}
.image-container img {
transition: transform 0.3s ease;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="image-container">
<img src="path/to/your/image.jpg" alt="Example Image" />
</div>
<script>
$(document).ready(function() {
$('.image-container').hover(
function() {
$(this).find('img').css('transform', 'scale(1.2)');
},
function() {
$(this).find('img').css('transform', 'scale(1)');
}
);
});
</script>
</body>
</html>
overflow: hidden;
,确保放大后的图片不会溢出容器。overflow: hidden;
,确保放大后的图片不会溢出容器。transform
属性进行缩放,而不是改变width
和height
属性。transform
属性进行缩放,而不是改变width
和height
属性。通过以上方法,可以有效解决jQuery鼠标悬停图片放大过程中可能遇到的问题。
没有搜到相关的文章