点击预览放大图片(photoswipe插件)

news/2025/2/21 10:29:51/

图片预览插件  https://photoswipe.com/documentation/getting-started.html

简单适用方法

一 引入文件

<link rel="stylesheet" href="../res/photoswipe/4.1.1/photoswipe.min.css">
<link rel="stylesheet" href="../res/photoswipe/4.1.1/default-skin/default-skin.min.css">
<script src="../res/photoswipe/4.1.1/photoswipe.min.js"></script>
<script src="../res/photoswipe/4.1.1/photoswipe-ui-default.min.js"></script>

或者(直接使用cdn)

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/default-skin/default-skin.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe-ui-default.min.js"></script>

 

二 在body内添加div

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><!-- Background of PhotoSwipe. It's a separate element, as animating opacity is faster than rgba(). --><div class="pswp__bg"></div><!-- Slides wrapper with overflow:hidden. --><div class="pswp__scroll-wrap"><!-- Container that holds slides. PhotoSwipe keeps only 3 slides in DOM to save memory. --><div class="pswp__container"><!-- don't modify these 3 pswp__item elements, data is added later on --><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. --><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><!--  Controls are self-explanatory. Order can be changed. --><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><!-- Preloader demo https://codepen.io/dimsemenov/pen/yyBWoR --><!-- element will get class pswp__preloader--active when preloader is running --><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div> </div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>

三 定义js方法

var openPhotoSwipe = function(idx) {var pswpElement = document.querySelectorAll('.pswp')[0];var arr=myOrderInfo.obj.paymentVoucher.split(",");//arr=['http://xxx/a.jpg','http://xxx/b.jpg']"var items2=[];for(var i=0;i<arr.length;i++){var ob={src: arr[i],w: 1024,h: 1024};items2[items2.length]=ob;}// build items arrayvar items = [{html: '<div class="hello-slide"><h1>Hello world <a href="http://example.com">example.com</a></h1></div>'},{src: 'aa.jpg',w: 1024,h: 1024}];// define options (if needed)var options = {index:idx,//展示第几个(下标从0开始)// history & focus options are disabled on CodePen        history: false,focus: false,showAnimationDuration: 0,hideAnimationDuration: 0};var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items2, options);gallery.init();};

四 点击第x张图片,触发openPhotoSwipe(idx)方法,弹出图片

 openPhotoSwipe(idx);  

效果

 

 


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

相关文章

缩放图片抗锯齿

&#xff08;转&#xff09;Android中实现区域平均算法在图片缩放里的应用&#xff08;缩放图片抗锯齿&#xff09; 摘要&#xff1a;Android图片缩放效果较差&#xff0c;尤其是将大尺寸的图片缩放成小尺寸的图片时&#xff0c;即便是加了抗锯齿&#xff0c;锯齿现象也比较严重…

预览图片 支持放大缩小,旋转等功能

一开始使用layer实现预览效果&#xff0c;但是没有放大跟缩小功能&#xff0c;于是就又找了下&#xff0c;发现jquery下有一款viewer.js可以很好的预览图片和各种功能。 包括图片的放大缩小旋转&#xff0c;可以很好的查看。 下面贴下jsp的 <!DOCTYPE html> <html&…

图片点击放大及切换图片

1. 编写html <div class"mask" id"mask"></div> <div class"img-container" id"img-container"><div class"preview" id"preview"></div><div class"left" id"…

如何把图片分辨率调低?如何调整照片的分辨率?

图像分辨率一般是指图像单位英寸内所包含的像素点数&#xff0c;一般用DPI表示单位&#xff0c;一张图像的文件大小一般是由图像的分辨率和尺寸共同决定的&#xff0c;分辨率与尺寸越大&#xff0c;图像越清晰&#xff0c;但是同样所需占用的空间就越大。在了解了关于图片分辨率…

照片放大啊

Description wth 的电脑里存储了一些老照片&#xff0c;虽然这些照片有些模糊&#xff0c;但是 wth 很喜欢它们&#xff0c;因为这些照片都是儿时的回忆。现在他上了大学&#xff0c;他想用学到的编程知识来将这些模糊的照片放大&#xff0c;可是他很菜&#xff0c;尝试了两年都…

easyui04(datagrid数据查询)

一.datagrid数据表格 <script type"text/javascript"> $(function(){ //加载数据 $(#myTable).datagrid({ url:ctx/goods.do,//请求路径 pagination:true,//显示分页栏 fitColumns:true,//让列…

Chrome 扩展程序——Imagus:图片放大预览工具

主要介绍 Imagus 的功能及应用&#xff0c;Imagus 是一款简单实用的图片放大预览工具。 主要功能 Imagus 的功能非常单一&#xff0c;就是在浏览网页时&#xff0c;当鼠标悬停到一张图片后&#xff0c;会自动放大图片&#xff0c;进行预览&#xff0c;这在浏览技术博客&#…

亲测好用的PS图片无损放大插件:Blow Up 3 for Mac

Alien Skin Blow Up 3 for Mac是一款运行在Mac平台上的PS图片无损放大滤镜插件&#xff0c;这款alienskin滤镜插件适用于ps和lr&#xff0c;使用alien skin blow up 3 for mac后&#xff0c;在放大图片的同时也能保持图片的清晰度&#xff0c;质量不变&#xff0c;非常好用。 A…