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 ...
随机推荐
- List(T)类的方法
List<T>.Clear 方法 List<T>.RemoveAll 方法 http://msdn.microsoft.com/zh-cn/library/s6hkc2c4(v ...
- java 时间戳和PHP时间戳 的转换[10位和13位]
2013-08-02 14:06 9826人阅读 评论(2) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. 总结一下java 时间戳和PHP时间戳 的转换问题: 由于精度不同,导 ...
- 赵雅智_android多线程下载带进度条
progressBar说明 在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度. 一个进度条也可不确定其进度.在不确定模式下, ...
- NET的基本用法(摘)
摘自:http://baike.baidu.com/link?url=Knc-OicoX8CPcaMS0r3eU8z8ns9z1S6OsRaBTYUIT1raU0FsPWQ35xL-dlxKg9Oy# ...
- AjaxControlToolkit的使用
摘自:http://www.cnblogs.com/zm235/archive/2008/05/09/1189558.html 暂时的做法: 把AjaxControlToolkit.dll复制到项目的 ...
- 【LeetCode】144. Binary Tree Preorder Traversal (3 solutions)
Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...
- IT常用设备及服务器安全公告或漏洞地址pa安全预警微软安全公告 HP 安全公告AIX 安全公告REDHAT安全公告ORACLE 安全公告F5 安全公告 Cisco 安全公告Juniper 安全公告 VMware 安全公告IOS 安全公告
IT常用设备及服务器安全公告或漏洞地址: 微软安全公告 https://technet.microsoft.com/en-us/library/security/MS14-085 HP 安全公告 ht ...
- oracle各种常用管理sql及其他 ---待续
启动客户端工具:sqlplus /nolog 使用sysdba链接:conn / as sysdba; select * from dba_users; --查看数据库里面所有用户,前提是你是有dba ...
- Spring Boot之HelloWorld
视频网址:http://www.iqiyi.com/w_19ruksbpf1.html <project xmlns="http://maven.apache.org/POM/4.0. ...
- 关于 Chrome Console 查看DOM详情细节的奇思淫巧
我们期待打印出的dom效果如下: 但某些时候,打印出来,或者通过$0.$1.document.getElementById('####') 等方式打印出来的效果如下: 根据第一幅图我们不难看出,当打印 ...