jQuery 调用图片查看器通常是指使用 jQuery 插件或者自定义代码来实现一个简单的图片查看功能。这种查看器允许用户在一个弹出窗口或者覆盖层中查看图片,而不是直接在网页上浏览。
以下是一个简单的 jQuery 图片查看器的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery 图片查看器示例</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.9);
}
.modal-content {
display: block;
margin: auto;
width: 80%;
max-width: 700px;
}
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<img id="myImg" src="img_snow.jpg" alt="Snow" width="300" height="200">
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
<script>
$(document).ready(function(){
$("#myImg").click(function(){
$("#myModal").css("display","block");
$("#img01").attr("src", this.src);
$("#caption").text(this.alt);
});
$(".close").click(function(){
$("#myModal").css("display","none");
});
});
</script>
</body>
</html>
通过上述示例代码,你可以快速实现一个基本的图片查看器。如果需要更复杂的功能,可以考虑使用成熟的 jQuery 图片查看器插件,如 Lightbox 或 Fancybox。
领取专属 10元无门槛券
手把手带您无忧上云