Lightbox/弹窗

SmartPhoto - jquery 移动手机响应式图片查看插件

阿里云


SmartPhoto 是一款为移动手机量身打造的响应式图片查看 jquery 插件。它使用简单,在桌面设备中点击图片时会以 Lightbox 的方式来展示图片。在移动手机的小屏幕中,会以轮播图的方式来展示图片。SmartPhoto 响应式图片的特点有:

支持 pinch-in/pinch-out/drag/swipe 等手势操作

也想出现在这里?联系我们
创客主机

可以使用键盘或屏幕阅读器来进行访问

使用加速计移动图片

显示图片的 URL hash 地址

可以对图片进行分组

使用方法:

在页面中引入 smartphoto.css 和 smartphoto.js 文件。

  1. <link href="path/to/css/smartphoto.css" rel="stylesheet">
  2. <script src=""path/to/js/smartphoto.js"></script>

HTML 结构:

SmartPhoto 响应式图片的基本 HTML 结构如下:

  1. <a href="./assets/large-kuma.jpg" class="js-img-viwer" data-caption="描述1" data-id="kuma" data-group="0">
  2.   <img src="./assets/kuma.jpg" width="360"/>
  3. </a>
  4. <a href="./assets/large-rakuda.jpg" class="js-img-viwer" data-caption="描述2" data-id="rakuda" data-group="0">
  5.   <img src="./assets/rakuda.jpg" width="360"/>
  6. </a>
  7. <a href="./assets/large-sai.jpg" class="js-img-viwer" data-caption="描述3" data-id="sai" data-group="0">
  8.   <img src="./assets/sai.jpg" width="360"/>
  9. </a>

初始化插件:

在页面 DOM 元素加载完毕之后们可以通过下面的方法来初始化 SmartPhoto 响应式图片插件。

  1. const smartPhoto = require('smartphoto');

smartphoto.js-纯 js 方法

  1. document.addEventListener('DOMContentLoaded',function(){
  2.     new smartPhoto(".js-img-viwer");
  3. });

作为 jquery 插件

  1. $(function(){
  2.     $(".js-img-viwer").smartPhoto();
  3. });

配置参数:

SmartPhoto 响应式图片插件的可用配置参数有:

参数 默认值 描述
arrows true 是否显示前后导航按钮。
nav true 是否在底部显示导航缩略图。
useOrientationApi true 是否使用加速计移动图片。
resizeStyle 'fill' resize 图像时是 fill 还是 fit 屏幕。
animationSpeed 300 切换图片时的动画速度。
forceInterval 10 frequency to apply force to images

事件:

SmartPhoto 响应式图片插件的可用事件有:

  1. // when the modal opened
  2. photo.on('open',function(){
  3.     console.log('open');
  4. });
  5. // when the modal closed
  6. photo.on('close',function(){
  7.     console.log('close');
  8. });
  9. // when all images are loaded
  10. photo.on('loadall',function(){
  11.     console.log('loadall');
  12. });
  13. // when photo is changed
  14. photo.on('change',function(){
  15.     console.log('change');
  16. });
  17. // when swipe started
  18. photo.on('swipestart',function(){
  19.     console.log('swipestart');
  20. });
  21. // when swipe ended
  22. photo.on('swipeend',function(){
  23.     console.log('swipeend');
  24. });
  25. // when zoomed in
  26. photo.on('zoomin',function(){
  27.     console.log('zoomin');
  28. });
  29. // when zoomed out
  30. photo.on('zoomout',function(){
  31.     console.log('zoomout');
  32. });

SmartPhoto 响应式图片插件的 github 地址为:https://github.com/appleple/SmartPhoto

SmartPhoto - jquery 移动手机响应式图片查看插件

已有 532 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!