jQuery 图片折叠效果是一种通过 jQuery 库实现的动态网页效果,通常用于图片的展开和折叠。这种效果可以增强用户体验,使网页内容更加生动和有趣。
以下是一个简单的 jQuery 图片折叠效果的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 图片折叠效果</title>
<style>
.image-container {
width: 300px;
height: 200px;
overflow: hidden;
}
.image-container img {
width: 100%;
height: auto;
transition: height 0.5s ease;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="image-container">
<img src="https://via.placeholder.com/300x150" alt="图片" id="folded-image">
<img src="https://via.placeholder.com/300x300" alt="展开图片" id="full-image" style="height: 0;">
</div>
<button id="toggle-button">展开/折叠</button>
<script>
$(document).ready(function() {
$('#toggle-button').click(function() {
if ($('#full-image').height() === 0) {
$('#folded-image').height(0);
$('#full-image').height('auto');
} else {
$('#full-image').height(0);
$('#folded-image').height('auto');
}
});
});
</script>
</body>
</html>
通过以上示例代码和解释,你应该能够实现一个简单的 jQuery 图片折叠效果,并解决常见的开发问题。
没有搜到相关的文章