在幻灯片自定义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. WCF简单案例

    1,定义接口层,引用System.ServiceModel namespace Contracts { [ServiceContract(Name = "CalculatorService& ...

  2. m4a文件在iOS上的流媒体播放

    Date: 2016-03-23 Title: m4a文件在iOS上的流媒体播放 Tags: m4a, mp4, iOS, Android URL: m4a-streaming-play-on-mob ...

  3. 用Broadcast Receiver刷新数据(二)

    采用消息发布/订阅的一个很大的优点就是代码的简洁性,并且能够有效地降低消息发布者和订阅者之间的耦合度.举个例子,比如有两个界面,ActivityA和ActivityB,从ActivityA界面跳转到A ...

  4. 关于C#我今天的六个小时

    嘿嘿,今天周六啦,我们是自由学习啦,于是还记得前几天纠结的事情,还有好多不太熟悉的题目那,于是今天就找出来练习下拉,而且这些题目在老师给我们复习时间也给我们讲解过啦,这样一来应该做起来还是容易点的啦, ...

  5. JS面向对象编程学习

    学习目标:1.掌握JS中的类(原型对象)和对象.2.什么是成员变量和成员方法.3.掌握构造方法的使用.补充:关于双等号(==):1.如果等号两边都是字符串时,则比较内容是否相等2.如果等号两边是数字时 ...

  6. xcode 4.6 破解及真机调试

    从安卓到IOS,从  eclipse 到xcode跨度还是比较大的.在研究的过程中发现,许多时候不仅仅是C,C++,JAVA和OBJECT-C的区别,相对于编程语言来说,操作习惯和开发工具带来的困惑要 ...

  7. LeetCode——Search a 2D Matrix II

    Description: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix ...

  8. bootstrap之按钮和图片

    一.按钮 类 描述 .btn 为按钮添加基本样式 .btn-default 默认/标准按钮 .btn-primary 原始按钮样式(未被操作) .btn-success 表示成功的动作 .btn-in ...

  9. iPad - 开发(Universal Applications)

    一.iPad 1.判断是否在iPad上 BOOL iPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdi ...

  10. OC开发_Storyboard——AutoLayout

    一.autolayout 自动布局: 1. 设置所有视图框架的三种方法,可以通过代码创建也可以storyboard设置 = 规则 (1 蓝线+约束:(位置) 使用蓝线,根据蓝线拖动控件,只是告诉Xco ...