js photoswipe 相册使用 移动pc端均可

<link rel="stylesheet prefetch" href="${baseURL}/js/3rd-plug/PhotoSwipe-4.1.1/photoswipe.css"><link rel="stylesheet prefetch" href="${baseURL}/js/3rd-plug/PhotoSwipe-4.1.1/default-skin/default-skin.css"><script src="${baseURL}/js/3rd-plug/PhotoSwipe-4.1.1/photoswipe.js"></script><script src="${baseURL}/js/3rd-plug/PhotoSwipe-4.1.1/photoswipe-ui-default.min.js"></script>
<!-- Root element of PhotoSwipe. Must have class pswp. --><div class="pswp" tabindex="-1" role="dialog" aria-hidden="true" style="top: 40px;height: 95%;"><!-- 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 of them in the DOM to save memory.Don't modify these 3 pswp__item elements, data is added later on. --><div class="pswp__container"><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 http://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" style="visibility: visible" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" style="visibility: visible" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>
var initPhotoSwipeFromDOM = function(gallerySelector) {// parse slide data (url, title, size ...) from DOM elements// (children of gallerySelector)var parseThumbnailElements = function(el) {var thumbElements = el.childNodes,numNodes = thumbElements.length,items = [],figureEl,linkEl,size,item;for(var i = 0; i < numNodes; i++) {figureEl = thumbElements[i]; // <figure> element// include only element nodesif(figureEl.nodeType !== 1) {continue;}linkEl = figureEl.children[0]; // <a> elementsize = linkEl.getAttribute('data-size').split('x');// create slide objectitem = {src: linkEl.getAttribute('href'),w: parseInt(size[0], 10),h: parseInt(size[1], 10)};if(figureEl.children.length > 1) {// <figcaption> contentitem.title = figureEl.children[1].innerHTML;}if(linkEl.children.length > 0) {// <img> thumbnail element, retrieving thumbnail urlitem.msrc = linkEl.children[0].getAttribute('src');}item.el = figureEl; // save link to element for getThumbBoundsFnitems.push(item);}return items;};// find nearest parent elementvar closest = function closest(el, fn) {return el && ( fn(el) ? el : closest(el.parentNode, fn) );};// triggers when user clicks on thumbnailvar onThumbnailsClick = function(e) {e = e || window.event;e.preventDefault ? e.preventDefault() : e.returnValue = false;var eTarget = e.target || e.srcElement;// find root element of slidevar clickedListItem = closest(eTarget, function(el) {return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');});if(!clickedListItem) {return;}// find index of clicked item by looping through all child nodes// alternatively, you may define index via data- attributevar clickedGallery = clickedListItem.parentNode,childNodes = clickedListItem.parentNode.childNodes,numChildNodes = childNodes.length,nodeIndex = 0,index;for (var i = 0; i < numChildNodes; i++) {if(childNodes[i].nodeType !== 1) {continue;}if(childNodes[i] === clickedListItem) {index = nodeIndex;break;}nodeIndex++;}if(index >= 0) {// open PhotoSwipe if valid index foundopenPhotoSwipe( index, clickedGallery );}return false;};// parse picture index and gallery index from URL (#&pid=1&gid=2)var photoswipeParseHash = function() {var hash = window.location.hash.substring(1),params = {};if(hash.length < 5) {return params;}var vars = hash.split('&');for (var i = 0; i < vars.length; i++) {if(!vars[i]) {continue;}var pair = vars[i].split('=');if(pair.length < 2) {continue;}params[pair[0]] = pair[1];}if(params.gid) {params.gid = parseInt(params.gid, 10);}return params;};var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {var pswpElement = document.querySelectorAll('.pswp')[0],gallery,options,items;items = parseThumbnailElements(galleryElement);// define options (if needed)options = {// define gallery index (for URL)galleryUID: galleryElement.getAttribute('data-pswp-uid'),getThumbBoundsFn: function(index) {// See Options -> getThumbBoundsFn section of documentation for more infovar thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnailpageYScroll = window.pageYOffset || document.documentElement.scrollTop,rect = thumbnail.getBoundingClientRect();return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};},closeEl:false,fullscreenEl : false, // 是否支持全屏按钮zoomEl: true,shareEl: false,counterEl: true,arrowEl: true,preloaderEl: true,closeOnScroll:false,arrowKeys:true};// PhotoSwipe opened from URLif(fromURL) {if(options.galleryPIDs) {// parse real index when custom PIDs are used// http://photoswipe.com/documentation/faq.html#custom-pid-in-urlfor(var j = 0; j < items.length; j++) {if(items[j].pid == index) {options.index = j;break;}}} else {// in URL indexes start from 1options.index = parseInt(index, 10) - 1;}} else {options.index = parseInt(index, 10);}// exit if index not foundif( isNaN(options.index) ) {return;}if(disableAnimation) {options.showAnimationDuration = 0;}// Pass data to PhotoSwipe and initialize itgallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);gallery.init();};// loop through all gallery elements and bind eventsvar galleryElements = document.querySelectorAll( gallerySelector );for(var i = 0, l = galleryElements.length; i < l; i++) {galleryElements[i].setAttribute('data-pswp-uid', i+1);galleryElements[i].onclick = onThumbnailsClick;}// Parse URL and open gallery if it contains #&pid=3&gid=1var hashData = photoswipeParseHash();if(hashData.pid && hashData.gid) {openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true );}};
<div class="my-gallery" itemscope itemtype="http://schema.org/ImageGallery" style="display: none"><c:forEach items="${requestScope.housePhotoes}" var="housePhoto" ><figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"><a href="${housePhoto.photourl}" itemprop="contentUrl" data-size="1024x1024"><img src="${housePhoto.photourl}" itemprop="thumbnail" alt="Image description" /></a><figcaption itemprop="caption description">${housePhoto.photoDescrition}</figcaption></figure></c:forEach></div>
initPhotoSwipeFromDOM('.my-gallery');$(function(){$(".my-gallery").find('figure')[0].click()})
附件列表
js photoswipe 相册使用 移动pc端均可的更多相关文章
- [应用][js+css3]3D盒子导航[PC端]
CSS3构建的3D盒子之导航应用 1.在用css3构建的盒子表面,放上iframe,来加载导航页面. 2.鼠标左键按下移动可旋转盒子,寻找想要的网址. 3.左键单机盒子表面,将全屏现实所点盒子表面的网 ...
- js判断用户是在PC端或移动端访问
js如何判断用户是在PC端和还是移动端访问. 最近一直在忙我们团队的项目“咖啡之翼”,在这个项目中,我们为移动平台提供了一个优秀的体验.伴随Android平台的红火发展.不仅带动国内智能手机行业,而 ...
- 基于React.js网页版弹窗|react pc端自定义对话框组件RLayer
基于React.js实现PC桌面端自定义弹窗组件RLayer. 前几天有分享一个Vue网页版弹框组件,今天分享一个最新开发的React PC桌面端自定义对话框组件. RLayer 一款基于react. ...
- js实现一个可以兼容PC端和移动端的div拖动效果
前段时间写了一个简单的div拖动效果,不料昨天项目上正好需要一个相差不多的需求,就正好用上了,但是在移动端的时候却碰到了问题,拖动时候用到的三个事件:mousedown.mousemove.mouse ...
- JS判断android ios系统 PC端和移动端
最近公司上线移动端,需要根据不同的系统跳转到不同的产品页面,百度后发现这一段代码很好用,不但可以判断当前是什么系统,还能知道当前浏览器是什么内核,移动端PC端都已测试无问题! var browser ...
- JS判断终端设备跳转PC端、移动端相应的URL
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...
- js判断当前浏览器是pc端还是移动端
根据用户的访问设备的不同来显示不同的页面样式,主要是判断移动设备还是电脑浏览器访问的. 下面给出js判断处理代码,以作参考. <script type="text/javascript ...
- js判断是手机还是PC端
有时接触一些手机上的适应,需要知道是pc 还是移动端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = [ ...
- js 判断移动设备、pc端、android、iPhone、是否为微信、微博、qq空间
varbrowser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersio ...
随机推荐
- 【Oracle】性能优化
优化原则 1.在select语句中避免使用* 2.使用Truncate清空表 2.1语法 Truncate [table|cluster] shema.[table_name][cluster_nam ...
- 各种HTTPS站点的SSL证书 ,扩展SSL证书,密钥交换和身份验证机制汇总
各种HTTPS站点的SSL证书 ,扩展SSL证书,密钥交换和身份验证机制汇总 一份常见的 HTTPS 站点使用的证书和数据加密技术列表,便于需要时比较参考,将持续加入新的 HTTP 站点,这里给出的信 ...
- Loadrunner脚本编程(4)-数据类型操作和字符串操作
http://www.360doc.com/content/10/0806/13/1698198_44078277.shtml 一,数据类型转换 没有使用过C编程的LoadRunner脚本编写者会发现 ...
- vs2017预览版下载
vs2017预览版,没有限制的不过不能生成生产版本,集成最新的功能! 下载地址: https://www.visualstudio.com/zh-hans/vs/preview/
- 网线/双绞线上各标识CAT, AWG, PR, UTP/STP/FTP/SFTP的含义
CAT5, CAT5e, CAT6 表示网线类别, 常见的有 CAT5, CAT5e, CAT6分别表示五类, 超五类, 六类网线 24AWG, 26AWG American Wire Gauge是美 ...
- linux配置server笔记
设置防火墙开放80port -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 尽管看不懂是什么,可是这个是用于开放80p ...
- Spring Framework Ecosystem – Introduction to Spring Projects
来自于:http://springtutorials.com/spring-ecosystem/ Hello and Welcome to Spring Tutorials Blog! Is it f ...
- Linux-Memcache和Redis常用命令
Memcache: 支持类型: String add, delete, set, replace, get, flush_all, stats, stats reset, stats i ...
- 使用增强for循环遍历集合的时候操作集合的问题?
// 遍历一个list public static void printList(List<String> list){ for (String string : list) { list ...
- ras api win7 和 win xp 遍历时的不同
由于在调用RasEnumEntries和RasEnumConnections在xp和win7以上的操作系统中有所不同,所以在win7下正常的代码在xp不一定就可以. 主要是在win7 下可以给参数传N ...