PhotoSwipe中文API(四)
在幻灯片自定义HTML内容
为了使PhotoSwipe显示HTML内容的幻灯片,你需要在幻灯片对象定义html属性。它应该包含HTML字符串或DOM元素对象。
var items = [
// slide 1 with HTML
{
html: '<div><h1>Any HTML <a href="http://example.com">content</a></h1></div>'
}, // slide 2 with image
{
src: 'path/to/image.jpg',
w:600,
h:200
}
]; // initialise as usual
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); // You don't necessarily need to have "html" property in slide object initially.
// You may create it dynamically in gettingData event:
/*
gallery.listen('gettingData', function(index, item) {
if(index === 3) {
item.html = '<div>Dynamically generated HTML ' + Math.random() + '</div>';
} });
*/ // Note that init() method is called after gettingData event is bound
gallery.init();
其他重要事项:
为了避免与第三方模块,具有html属性幻灯片冲突,不应该有SRC(图像)属性。
PhotoSwipe是专为图像,而不是文本内容的滚轮。使用“自定义HTML”功能作为此外,例如,在相关的画廊,一个介绍的幻灯片,或图像之间的广告幻灯片。
我们强烈不建议添加视频或使用此方法的音频内容(包括YouTube,Vimeo的等内部框架)。随着HTML5视频块触摸了它的活动在很多移动浏览器(用户将无法刷卡的话)。如果你真的需要在PhotoSwipe视频,您可以将其添加为当用户点击当前的幻灯片显示模式,可以动态地在DOM创建模态和.pswp__scroll换行元素之后添加它。
如果启用了最初的放大/缩小的过渡,如果当前的幻灯片有HTML PhotoSwipe将自动禁用它,简单的淡入淡出的过渡将被用来代替。
默认情况下PhotoSwipe将使只是链接(<A>)及其子元素click事件。要改变这种行为,直视isClickable元素选项或防止拖动事件的事件。
不支持HTML滑块的放大,但。
html:
<button id="btn">Open PhotoSwipe</button> <!-- 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 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" 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>
css :
 .hello-slide {
   width: 100%;
   max-width: 400px;
   color: #FFF;
   margin: 120px auto 0;
   text-align: center;
   font-family: "Helvetica Neue", Arial, sans-serif;
 }
 h1 {
   font-weight: normal;
 }
 .hello-slide a {
   color: #B5AEF7 !important;
 }
js:
 var openPhotoSwipe = function() {
     var pswpElement = document.querySelectorAll('.pswp')[0];
     // build items array
     var items = [
         {
         html: '<div class="hello-slide"><h1>Hello world <a href="http://example.com">example.com</a></h1></div>'
     },
         {
             src: 'https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg',
             w: 1024,
             h: 683
         }
     ];
     // define options (if needed)
     var options = {
              // history & focus options are disabled on CodePen
         history: false,
         focus: false,
         showAnimationDuration: 0,
         hideAnimationDuration: 0
     };
     var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
     gallery.init();
 };
 openPhotoSwipe();
 document.getElementById('btn').onclick = openPhotoSwipe;

提示:您可以从CodePen下载示例在本地发挥它(编辑上CodePen - >分享 - >导出.zip文件)。
PhotoSwipe中文API(四)的更多相关文章
- PhotoSwipe中文API(三)
		
http://photoswipe.com/documentation/api.html 所有的方法和这个网页上列出的属性是公开的.如果你想看看例子什么API可以做的,拿在默认PhotoSwipe U ...
 - PhotoSwipe中文API(一)
		
入门 您应知道之前先做起事情: 1. PhotoSwipe不是一个简单的jQuery插件,至少基本的JavaScript知识才能安装. 2. PhotoSwipe需要预定义的图像尺寸(更多关于这一点) ...
 - PhotoSwipe中文API(二)
		
配置 选项是在键 - 值对添加作为参数传递给PhotoSwipe构造,例如通过: var options = { index: 3, escKey: false, // ui option timeT ...
 - PhotoSwipe中文API(五)
		
Responsive Images PhotoSwipe不支持<图片>或srcset,因为它要求所定义的图像的尺寸,并使用延迟加载.但是,随着图像动态加载,它很容易切换人士透露,即便是在旧 ...
 - Android JNI学习(四)——JNI的常用方法的中文API
		
本系列文章如下: Android JNI(一)——NDK与JNI基础 Android JNI学习(二)——实战JNI之“hello world” Android JNI学习(三)——Java与Nati ...
 - Android 中文 API (40) —— RatingBar
		
Android 中文 API (40) —— RatingBar 前言 本章内容是 android.widget.RatingBar,译为"评分条",版本为Android 2.2 ...
 - (转)jQuery验证控件jquery.validate.js使用说明+中文API
		
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
 - Android 中文API (70) —— BluetoothDevice[蓝牙]
		
前言 本章内容是 android.bluetooth.BluetoothDevice,为Android蓝牙部分的章节翻译.蓝牙设备类,代表了蓝牙通讯国足中的远端设备.版本为 Android 2.3 ...
 - Android 中文API (69) —— BluetoothAdapter[蓝牙]
		
前言 本章内容是 android.bluetooth.BluetoothAdapter,为Android蓝牙部分的章节翻译.本地蓝牙设备的适配类,所有的蓝牙操作都要通过该类完成.版本为 Androi ...
 
随机推荐
- C++与Java混合编程
			
现在的程序员,不再像以前一样,掌握一种编程语言就可以混得有模有样了,现实的情况是,真实的项目中,通常是涉及多种编程语言,举几个简单的例子,一个软件为了快速开发,可能是使用Delphi或VB作为界面开发 ...
 - Git高级操作
			
本文是在Git操作指南基础上衍生出来的高级操作,如果你对git不是很熟悉,建议你先阅读Git操作指南. 一.忽略提交特定文件 如果你不想让一些文件上传到git仓库中,可以让Git忽略特定文件或是目录, ...
 - RabbitMQ消息确认(发送确认,接收确认)
			
前面几篇记录了收发消息的demo,今天记录下关于 消息确认方面的 问题. 下面是几个问题: 1.为什么要进行消息确认? 2.rabbitmq消息确认 机制是什么样的? 3.发送方如何确认消息发送成功? ...
 - 【渗透测试学习平台】 web for pentester -4.目录遍历
			
Example 1 http://192.168.106.154/dirtrav/example1.php?file=../../../../../../../etc/passwd Example 2 ...
 - Linux 防火墙:Netfilter
			
一.Netfilter 简介 (1) Netfilter 是 Linux 内置的一种防火墙机制,我们一般也称之为数据包过滤机制,而 iptables 只是操作 netfilter 的一个命令行工具(2 ...
 - 如何设置SOLR的高亮 (highlight)?
			
打开SOLR的核心配置文件: solrconfig.xml 找到 standard request handler 写入以下XML配置代码: <requestHandler name=" ...
 - 使用类/结构体时关于ZeroMomery用法错误
			
今天同事在写了如下结构体: typedef struct _tagInfo { std::list<int> lst; std::vector<int> nVec; } INF ...
 - PyQt4状态栏
			
主窗口 QMainWindow类用来创建应用程序的主窗口.通过该类,我们可以创建一个包含状态栏.工具栏和菜单栏的经典应用程序框架. 状态栏是用来显示状态信息的串口部件. #!/usr/bin/pyth ...
 - Android 基于帧布局实现一个进度条 FrameLayout+ProgressBar
			
在FrameLayout中添加一个ProgressBar居中 <ProgressBar android:layout_gravity="center" android:id= ...
 - openstack将本地实例迁移至ceph存储中
			
需求: 最近在openstack上线了ceph存储,创建虚拟机和云硬盘都基于ceph卷进行存储和创建,但是之前openstack用的是本地存储,创建的所有实例都在本地文件中,当实例重启之后,opens ...