在幻灯片自定义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(四)的更多相关文章

  1. PhotoSwipe中文API(三)

    http://photoswipe.com/documentation/api.html 所有的方法和这个网页上列出的属性是公开的.如果你想看看例子什么API可以做的,拿在默认PhotoSwipe U ...

  2. PhotoSwipe中文API(一)

    入门 您应知道之前先做起事情: 1. PhotoSwipe不是一个简单的jQuery插件,至少基本的JavaScript知识才能安装. 2. PhotoSwipe需要预定义的图像尺寸(更多关于这一点) ...

  3. PhotoSwipe中文API(二)

    配置 选项是在键 - 值对添加作为参数传递给PhotoSwipe构造,例如通过: var options = { index: 3, escKey: false, // ui option timeT ...

  4. PhotoSwipe中文API(五)

    Responsive Images PhotoSwipe不支持<图片>或srcset,因为它要求所定义的图像的尺寸,并使用延迟加载.但是,随着图像动态加载,它很容易切换人士透露,即便是在旧 ...

  5. Android JNI学习(四)——JNI的常用方法的中文API

    本系列文章如下: Android JNI(一)——NDK与JNI基础 Android JNI学习(二)——实战JNI之“hello world” Android JNI学习(三)——Java与Nati ...

  6. Android 中文 API (40) —— RatingBar

    Android 中文 API (40) —— RatingBar 前言 本章内容是 android.widget.RatingBar,译为"评分条",版本为Android 2.2 ...

  7. (转)jQuery验证控件jquery.validate.js使用说明+中文API

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...

  8. Android 中文API (70) —— BluetoothDevice[蓝牙]

    前言 本章内容是  android.bluetooth.BluetoothDevice,为Android蓝牙部分的章节翻译.蓝牙设备类,代表了蓝牙通讯国足中的远端设备.版本为 Android  2.3 ...

  9. Android 中文API (69) —— BluetoothAdapter[蓝牙]

    前言 本章内容是  android.bluetooth.BluetoothAdapter,为Android蓝牙部分的章节翻译.本地蓝牙设备的适配类,所有的蓝牙操作都要通过该类完成.版本为 Androi ...

随机推荐

  1. jQuery页面刷新(局部、全部)问题分析

    本文实例分两部分对jquery刷新问题进行介绍,第一部分介绍了呢页面局部刷新:第二部分介绍了页面全部刷新第一:页面局部刷新 jQuery对Ajax操作进行了封装,在jQuery中$.ajax()方法属 ...

  2. 怎样用MathType创建竖式算法

    在使用MathType编辑公式时,有时将最简单的表达式变成Word文档也会出现一些问题.比如MathType竖式.下面介绍MathType竖式的一些编辑方法. 步骤如下: 步骤一:在MathType底 ...

  3. 无法在Word中打开MathType怎么办

    MathType是一种数学公式编辑器,通常我们都是与Office文档配合使用,但是如果大家在Word中使用MathType编辑公式时,遇到MathType无法打开的情况,我们应该怎么办?下面我们就针对 ...

  4. html5 经验记录 持续更新

    1 关于page cache 由于移动端浏览器webkit基本都实现了page cache(火狐叫做back-forwoad cache);所以回退操作基本不会触发onload操作了,不过上一页的状态 ...

  5. C# Serializable(转)

    C# Serializable System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时,所有的实例数据都保存到存储介质上,在取消串行 ...

  6. [转]ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB

    您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...

  7. rac_grid自检提示缺少cvuqdisk包

    原创作品,出自 "深蓝的blog" 博客,欢迎转载.转载时请务必注明下面出处.否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  8. python2.0_s12_day10_rabbitMQ使用介绍

    RabbitMQ RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消息队列(M ...

  9. CentOS5.5环境下布署LVS+keepalived

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/401253 #!/bin ...

  10. css纯字母或者字母换行显示

    white-space:normal; word-break:break-all;