点击图片放大预览,遮罩屏幕放大展示

news/2025/2/22 6:29:31/

功能说明:将图片方格展示,点击某张图片可在当前页面进行预览,点击遮罩屏幕,并且方法显示,点击右上角x,放大的图片消失。

效果图如下:

1、引入fancy.js和fancy.css

路径根据项目实际路径改写:

<link href="../static/fancybox/fancybox.css" type="text/css" rel="stylesheet"/>
<script src="../static/fancybox/fancybox.js" type="text/javascript"></script>

关于这两个文件以及其中用到的图片,我将其上传至csdn,可以下载(本想不用积分可以下载,但是编辑没找到可以自定义下载积分的。。。如果读者有需要的可以邮箱联系我:christicana@foxmail.com):

https://download.csdn.net/download/luuvyjune/11100319

 

2、html片段:

<div class="container"><div class="content-box"><div class="text-box"><ul class="ul-qualification"><c:forEach items="${fn:split(article.image,'|')}" var="img" varStatus="xh"><li class="mid"><div class="img-box"><a href="${img}" class="fancybox" title="风景如画" rel="group746"><img onload="resizeImg(this, 280, 190)" src="${img}" alt=""></a></div><div class="video-title" title="风景如画">风景如画</div></li></c:forEach></ul></div></div>
</div>

2、css布局:

<style>.container .content-box {width: 100%;height: auto;/*padding-left: 180px;*/box-sizing: border-box;padding-bottom: 20px;}.container .content-box .text-box {width: 100%;height: auto;overflow: hidden;margin-top: 20px;text-align: justify;}.container .content-box .text-box ul.ul-qualification {margin: 0;padding: 0;list-style: none;}.container .content-box .text-box ul.ul-qualification li {width: 290px;height: 245px;float: left;margin-bottom: 35px;border: 1px solid #b6b2b3;box-shadow: 3px 3px 8px #999;}.container .content-box .text-box ul.ul-qualification li.mid {margin: 0 26px 35px 10px;}.container .content-box .text-box ul.ul-qualification li .img-box {width: 275px;height: 185px;box-sizing: border-box;margin: 10px auto 0 auto;}.container .content-box .text-box ul.ul-qualification li .video-title {width: 100%;height: 50px;line-height: 50px;text-align: center;font-size: 16px;color: #000;box-sizing: border-box;}</style>

3、js片段:

<script type="text/javascript">$(document).ready(function () {         $(".fancybox").fancybox();});function resizeImg(ImgID, FitWidth, FitHeight) {var image = new Image();image.src = ImgID.src;imgWidth = image.width;imgHeight = image.height;if (imgWidth > 0 && imgHeight > 0) {if (imgWidth < FitWidth && imgHeight < FitHeight) {ImgID.style.marginTop = (FitHeight - imgHeight) / 2 + "px";ImgID.style.marginLeft = (FitWidth - imgWidth) / 2 + "px";} else {if (imgWidth >= imgHeight) {//图片宽大于图片高,缩小高度var imgH = (imgHeight * FitWidth) / imgWidth;ImgID.width = FitWidth;ImgID.height = imgH;ImgID.style.marginTop = (FitHeight - imgH) / 2 + "px";} else {//图片宽小于图片高,缩小宽度var imgW = (imgWidth * FitHeight) / imgHeight;ImgID.width = (imgWidth * FitHeight) / imgHeight;ImgID.height = FitHeight;ImgID.style.marginLeft = (FitWidth - imgW) / 2 + "px";}}}}    </script>

 


http://www.ppmy.cn/news/424239.html

相关文章

如何把图片无损放大?教你图片怎么无损放大

随着数字图像技术的不断发展&#xff0c;图片无损放大成为了许多人关注的问题。当我们需要将小图片放大到更大的尺寸时&#xff0c;使用传统的放大方法可能会导致图片失真、模糊等质量问题。那么如何在保持高清晰度和精度的同时进行无损放大&#xff0c;一直是一个备受关注的课…

2023年英语六级作文模板

根据主题灵活进行修改&#xff0c;总字数217 In the contemporary world, with the rapid advance of science and technology, it’s great necessity for youngsters on campus to grasp digital skills. Reason and concrete evidence to support my view point are as fo…

mNGS 02:SnakeMake流程简介

<~生~信~交~流~与~合~作~请~关~注~公~众~号生信探索> 流程代码在&#xff1a;https://jihulab.com/BioQuest/SnakeMake-mNGS 或https://github.com/BioQuestX/SnakeMake-mNGS 教程链接在&#xff1a;https://doc.bioquest.cn/mngs mNGS Pipeline summary Metagenomic nex…

springboot redis实现缓存的例子

好的&#xff0c;下面是带注释的代码&#xff1a; 1. 添加Redis依赖&#xff1a; <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId> </dependency>2. 配置Redis连接&am…

vue3 route跳转的new tab两种方式

Vue有两种类型的应用SPA和MAP&#xff0c;本文主要介绍的是SPA类型下面的使用方法 SPA (single page application) 单页面应用&#xff0c;即一个web项目就只有一个页面&#xff08;即一个HTML文件&#xff09; 这种类型通常都需要router来进行页面跳转. 一开始只需要加载一…

苹果手机如何调节屏幕彩色(对于百度提供的方式行不通时此方法必有用)

苹果手机如何调节屏幕彩色(对于百度提供的方式行不通时此方法必有用) 1.用3个手指快速点击屏幕3次&#xff0c;出现以下画面 2.选取滤镜&#xff0c;出现以下屏幕 3.选择无&#xff0c;就会恢复彩色屏幕了 4.总结是孩子或不小心误触到屏幕上的隐藏功能导致屏幕黑白色&#xf…

发一个android系统手机的屏幕校准软件

我自己还没看。 http://www.diypda.com/forum.php?modviewthread&tid306089 http://www.rin9.com/read.php?tid941566

苹果手机屏幕上有白点怎么办

想要关闭苹果手机屏幕上的白点&#xff0c;先进入设置&#xff0c;找到通用&#xff0c;选择辅助功能。进入辅助功能页面之后&#xff0c;页面下滑&#xff0c;点击Assistive Touch选项&#xff0c;接着继续点击右上角的按钮&#xff0c;使其调整为关闭的状态&#xff0c;屏幕上…