Images preview component for web pages on touch device.
Consider use imagebox for browser images on desktop browsers.
Visit demo with your phone
It's already used in production at jiangwoo
The standalone file could be ~12kb, if you use webpack and reuse components like tween, the increased file size could be much smaller.
- Swipe, pinchzoom and scroll (when necessary) event support.
- Tap to show and hide.
- Scale in and out current image with animation.
- Min & max zoom limitation.
- Src convert and loading effect for display original image.
npm install images-preview -S
Or use standalone file preview.js
Include style.css to your page.
For webpack user:
import ImagePreview from 'image-preview'
let imgs = document.querySelectorAll('img')
new ImagePreview(imgs)
For standalone file user:
// add standalone file to your html
<script type="text/javascript" src="preview.js"></script>
// create an instance
var ImagesPreview = window.ImagesPreview.default;
new ImagesPreview(picture, {
convert: function(src) {
return src;
}
});
show
emitted on container shown.hide
emitted on container hide.active
emitted withindex
on active item change.
Constructor for ImagePreview, when tap event is fired on one of imgs
, a
preview container is shown for user to swipe and/or pinchzoom.
imgs
is original images collection.option
optional options.option.convert
a function used to return orignal image url fromcurrentSrc
of current image.option.bind
not bind tap event when ===false
Show/hide container.
Active a specfic image
img
compressed image element.idx
index ofimg
in image list (allows active image from img outside initialized images).animate
use animation if true.
Unbind tap event.
Copyright 2016 [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.