Code Monkey home page Code Monkey logo

smartphoto's Introduction

SmartPhoto

npm version CircleCI npm download GitHub license

The most easy to use responsive image viewer especially for mobile devices

See https://appleple.github.io/SmartPhoto/ for complete docs and demos
If you are Japasese, See here https://www.appleple.com/blog/javascript/smartphoto-js.html instead.

Feature

  • Intuitive gestures such as pinch-in/pinch-out/drag/swipe
  • Use Accelerometer to move images
  • Accessible from keyboards and screen-readers
  • Show pictures via URL hash
  • Can make photo groups

Installation

via npm

npm install smartphoto --save

or yarn

yarn add smartphoto

Usage

require

const SmartPhoto = require('smartphoto');

smartphoto.js

document.addEventListener('DOMContentLoaded',function(){
    new SmartPhoto(".js-smartphoto");
});

jquery-smartphoto.js

$(function(){
    $(".js-smartphoto").SmartPhoto();
});

Basic Standalone Usage

<a href="./assets/large-bear.jpg" class="js-smartphoto" data-caption="bear" data-id="bear" data-group="0">
  <img src="./assets/bear.jpg" width="360"/>
</a>
<a href="./assets/large-camel.jpg" class="js-smartphoto" data-caption="camel" data-id="camel" data-group="0">
  <img src="./assets/camel.jpg" width="360"/>
</a>
<a href="./assets/large-rhinoceros.jpg" class="js-smartphoto" data-caption="rhinoceros" data-id="sai" data-group="0">
  <img src="./assets/rhinoceros.jpg" width="360"/>
</a>
<link rel="stylesheet" href="./css/smartphoto.min.css">
<script src="./js/smartphoto.js"></script>
<script>
document.addEventListener('DOMContentLoaded',function(){
  new SmartPhoto(".js-smartphoto");
});
</script>

Option

variable description default
arrows prev/next arrows true
nav navigation images at the bottom true
useOrientationApi use accelerometer to move images true
resizeStyle resize images to fill/fit on the screen 'fill'
animationSpeed animation speed when switching images 300
forceInterval frequency to apply force to images 10

Hide parts

document.addEventListener('DOMContentLoaded',function(){
    new SmartPhoto(".js-smartphoto",{
        arrows: false,
        nav: false
    });
});

Fit/Fill Option

You can choose if you want to scale images to fit/fill

document.addEventListener('DOMContentLoaded',function(){
  new SmartPhoto(".js-smartphoto",{
      resizeStyle: 'fit'
  });
});

Event

// when the modal opened
photo.on('open',function(){
    console.log('open');
});
// when the modal closed
photo.on('close',function(){
    console.log('close');
});
// when all images are loaded
photo.on('loadall',function(){
    console.log('loadall');
});
// when photo is changed
photo.on('change',function(){
    console.log('change');
});
// when swipe started
photo.on('swipestart',function(){
    console.log('swipestart');
});
// when swipe ended
photo.on('swipeend',function(){
    console.log('swipeend');
});
// when zoomed in
photo.on('zoomin',function(){
    console.log('zoomin');
});
// when zoomed out
photo.on('zoomout',function(){
    console.log('zoomout');
});

SCSS

variable description default
$animation-speed animation speed when switching images .3s
$backdrop-color backdrop color when viewing images rgba(0, 0, 0, 1)
$header-color header color rgba(0, 0, 0, .2)

Download

Download ZIP

Github

https://github.com/appleple/SmartPhoto

Contributor

@steelydylan

License

Code and documentation copyright 2017 by appleple, Inc. Code released under the MIT License.

smartphoto's People

Contributors

atsu666 avatar dependabot[bot] avatar johncrisostomo avatar kaile avatar mkasumi avatar steelydylan avatar uidev1116 avatar yoshi0207 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartphoto's Issues

bundleテスト

実際にnpmでインストールしてきてbundleして動作するかチェックする

url参数被你的hash整没了~~

本来url是 detail.html?id=1
qq 20171229171035

然后浏览图片后,url就被hash了,?id=1就被删除了,
qq 20171229171046

相册点击关闭之后,URL就变成 detail.html
qq 20171229171055

我的参数没了

simplify

instead of this:
<a href="./assets/large-kuma.jpg" class="js-smartPhoto" data-caption="bear" data-id="bear"> <img src="./assets/kuma.jpg" width="360" data-group="animal"/> </a>
this:
<img src="https://appleple.github.io/SmartPhoto/assets/images/kuma.jpg" class="js-smartPhoto"/>
In this way we can apply it to any image. It would be great for my content manager webforever.es

Addnewitem feature

Hi @steelydylan ,

Can you give me an example how to use addnewitem method on new dynamic image?
I use addnewitem to add new image, the item added but when I click the thumbnail it just display the preload image.
Please assist.
image

Thanks.

If images fail to load and image viewer is open, overlay is not removed from DOM when the viewer is closed

If the image is not available, and you attempt to open the image viewer, the viewer will display a progress/loading spinner. Closing the viewer using the top "X" close button, will successfully close the viewer, however there will be an invisible overlay left on top of the DOM preventing interaction with the application.

The console reveals a NPE on the attempt to close the viewer:

Uncaught (in promise) TypeError: Cannot read property 'style' of null
at smartphoto.min.js:104
at new Promise ()
at e.value (smartphoto.min.js:104)
at e.value (smartphoto.min.js:104)
at smartphoto.min.js:103
at HTMLDivElement. (smartphoto.min.js:103)

A bower install would be great :)

As for the title :) That's mainly because I use codekit app most of the time, and sadly it uses only bower.

Thank you for your great code!

Regards

Prevent the large image preloading

First of all,this plugin is very awesome,thank you so mach. But there are some shortcoming. For example, the origin images in the <a href="./assets/large-rakuda.jpg"></a> will be loaded at the same time.
So, how to prevent the origin image preloading?

image

jQuery version does not work

jQuery example does not work, after including all stuff, including script and clicking on example image, nothing happens, broken

Disable animations when opening images

Hey, brilliant plugin! I was wondering if it was possible to disable the animation effect when opening up an image? I'd prefer just for it to appear than transition up. The same with the fade out effect when closing the window.

Thanks!

Closing the viewer by the Back button

Hello @steelydylan,

I use SmartPhoto on mobiles and when I click the Back button on a smartphone I go to the previous page. Is any way to close the viewer if it's opened by the Back button? It can be inconveniently to use default close button (X) on smartphones.

Thanks,
Victor.

Are there any options for callback methods or events?

Great plugin!

Just wondering if there is any method by which we can hook into the events of the gallery?

For example, an option for a callback that can hook into firing once an image is opened, transitioned, loaded, navigated through etc etc.

If there's any undocumented way to do this I'd love to know! It'd be great to get this in the works if it doesn't exist already.

Thank you 👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.