PhotoSwipe中文API(五)
Responsive Images
PhotoSwipe不支持<图片>或srcset,因为它要求所定义的图像的尺寸,并使用延迟加载。但是,随着图像动态加载,它很容易切换人士透露,即便是在旧的浏览器不支持srcset。
让我们假设你只有“中等”的图片和“原始”(“大”)的图像。首先,你需要存储在幻灯片对象的图像的路径和大小,例如像这样:
var items = [ // Slide 1
{
mediumImage: {
src: 'path/to/medium-image-1.jpg',
w:800,
h:600
},
originalImage: {
src: 'path/to/large-image-1.jpg',
w: 1400,
h: 1050
}
}, // Slide 2
// {
// mediumImage: {
// src: 'path/to/medium-image-2.jpg',
// ...
//
// ... ];
Then:
// initialise as usual
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); // create variable that will store real size of viewport
var realViewportWidth,
useLargeImages = false,
firstResize = true,
imageSrcWillChange; // beforeResize event fires each time size of gallery viewport updates
gallery.listen('beforeResize', function() {
// gallery.viewportSize.x - width of PhotoSwipe viewport
// gallery.viewportSize.y - height of PhotoSwipe viewport
// window.devicePixelRatio - ratio between physical pixels and device independent pixels (Number)
// 1 (regular display), 2 (@2x, retina) ... // calculate real pixels when size changes
realViewportWidth = gallery.viewportSize.x * window.devicePixelRatio; // Code below is needed if you want image to switch dynamically on window.resize // Find out if current images need to be changed
if(useLargeImages && realViewportWidth < 1000) {
useLargeImages = false;
imageSrcWillChange = true;
} else if(!useLargeImages && realViewportWidth >= 1000) {
useLargeImages = true;
imageSrcWillChange = true;
} // Invalidate items only when source is changed and when it's not the first update
if(imageSrcWillChange && !firstResize) {
// invalidateCurrItems sets a flag on slides that are in DOM,
// which will force update of content (image) on window.resize.
gallery.invalidateCurrItems();
} if(firstResize) {
firstResize = false;
} imageSrcWillChange = false; }); // gettingData event fires each time PhotoSwipe retrieves image source & size
gallery.listen('gettingData', function(index, item) { // Set image source & size based on real viewport width
if( useLargeImages ) {
item.src = item.originalImage.src;
item.w = item.originalImage.w;
item.h = item.originalImage.h;
} else {
item.src = item.mediumImage.src;
item.w = item.mediumImage.w;
item.h = item.mediumImage.h;
} // It doesn't really matter what will you do here,
// as long as item.src, item.w and item.h have valid values.
//
// Just avoid http requests in this listener, as it fires quite often }); // Note that init() method is called after gettingData event is bound
gallery.init();
你不一定要使用幻灯片对象,看起来酷似以上(含mediumImage和largeImage对象)的结构。例如,您可以直接在图像文件名(/path/to/large-image-600x500.jpg)存储图像的大小,然后在gettingData事件解析大小。只有item.src,item.w和item.h属性由PhotoSwipe读取和gettingData事件被触发之后。
较大的图像,不太流畅的动画外观。
尽量避免服务只是基于设备像素比或只是基于视口大小的图像,始终两者结合起来。
随意的打开PhotoSwipe缩略图使用srcset。
Image Gallery SEO
PhotoSwipe不强制HTML标记,你有完全控制权。简单的标记是链接到大的图像,最简单的例子缩略图列表:
<a href="large-image.jpg">
<img src="small-image.jpg" alt="Image description" />
</a>
...
如果你有很长的标题,不适合在ALT或只是包含HTML标记,您可以使用<人物>和<figcaption>:
<figure>
<a href="large-image.jpg">
<img src="small-image.jpg" alt="Image description" />
</a>
<figcaption>Long image description</figcaption>
</figure>
...
你可以更进一步,使用Schema.org标记为ImageGallery和ImageObject,它应该是这样的:
<div itemscope itemtype="http://schema.org/ImageGallery"> <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="large-image.jpg" itemprop="contentUrl">
<img src="small-image.jpg" itemprop="thumbnail" alt="Image description" />
</a> <!-- optionally use this method to store image dimensions for PhotoSwipe -->
<meta itemprop="width" content="300">
<meta itemprop="height" content="600"> <figcaption itemprop="caption description">
Long image description <!-- optionally define copyright -->
<span itemprop="copyrightHolder">Photo: AP</span>
</figcaption>
</figure> <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="large-image.jpg" itemprop="contentUrl">
<img src="small-image.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Long image description</figcaption>
</figure> ... </div>
如果你不想缩略图是网页,例如可见你在画廊50幅图像,你只显示前3的缩略图+链接“查看所有图片(50)”,你一定要在链接元素的内容使用Schema.org标记,你应该有所有50个链接(文字,而不是缩略图)的DOM(你可能会显示隐藏:无)。 例:
<div itemscope itemtype="http://schema.org/ImageGallery"> <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="large-image-1.jpg" itemprop="contentUrl">
<figcaption itemprop="caption description">Long image description 1</figcaption>
</a>
</figure> <figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="large-image-2.jpg" itemprop="contentUrl">
<figcaption itemprop="caption description">Long image description 2</figcaption>
</a>
</figure> ... </div>
在上述所有情况下,大image.jpg文件将被完全索引。 - 不要关键字东西它没有,只是不停的文本相关的,非垃圾邮件:即使你带显示隐藏的标题元素将被抓取。
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(四)
在幻灯片自定义HTML内容 为了使PhotoSwipe显示HTML内容的幻灯片,你需要在幻灯片对象定义html属性.它应该包含HTML字符串或DOM元素对象. var items = [ // sli ...
- 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 ...
- Android JNI学习(四)——JNI的常用方法的中文API
本系列文章如下: Android JNI(一)——NDK与JNI基础 Android JNI学习(二)——实战JNI之“hello world” Android JNI学习(三)——Java与Nati ...
随机推荐
- OCX控件打包成CAB并实现数字签名过程
OCX打包CAB并签名过程 一.打包cab 制作cab文件时需要将所有的相关文件都包含进去,可以通过Depends(VC自带的)检查需要的文件.使用inf文件将这些东西都写进去. 1.制作inf文 ...
- 你真的了解HTML吗?–雅虎面试题
http://helloweb.wang/jingyan~jiqiao/589.html
- 什么是集群(Cluster)技术
什么是集群(Cluster)技术Cluster集群技术可如下定义:一组相互独立的服务器在网络中表现为单一的系统,并以单一系统的模式加以管理.此单一系统为客户工作站提供高可*性的服务.大多数模式下,集群 ...
- C#导出Excel按照指定格式设置单元格属性值
最近项目中一直在写XML.Table.Excel之间的转化.之前一直都是不考虑格式的导出,今天给出一个格式,让按照格式导出,还真把我这新手为难了一翻,网上给出的资料基本一样.为了一个单元格文字变色纠结 ...
- day06<面向对象>
面向对象(面向对象思想概述) 面向对象(类与对象概述) 面向对象(学生类的定义) 面向对象(手机类的定义) 面向对象(学生类的使用) 面向对象(手机类的使用) 面向对象(一个对象的内存图) 面向对象( ...
- 判断app是否是第一次启动
如何判断app是否是第一启动呢,第一次启动的时候,加载引导页面等, 一下是我的解决方案: 1.在"AppDelegate.h"中找到- (BOOL)application:(UIA ...
- mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现?
mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现? mysql中实现方式如下: select merchantId, NameCn, send_date, deliver_name ...
- Linux ulimit 命令
ulimit命令用来限制系统用户对 shell 资源的访问,常见用法如下: [root@localhost ~]$ ulimit -a # 查看当前所有的资源限制 [root@localhost ~] ...
- 开发人员必读openstack网络基础2:交换机、路由器、DHCP
我们在使用openstack的过程中,会遇到创建虚拟机路由器.交换机等,那么1.他们的作用到底是什么?2.DHCP为什么会产生,它的作用是什么? 个人总结:交换机:一般用在同一网段,工作在数据链路层, ...
- HTML - 分页效果布局
<p class="jcFY"> 显示 <select name="" id=""> <option valu ...