GithubHelp home page GithubHelp logo

nzbin / photoviewer Goto Github PK

View Code? Open in Web Editor NEW
343.0 6.0 52.0 2.09 MB

🖼️ A JS plugin to view images just like in Windows.

Home Page: https://nzbin.github.io/photoviewer/

License: MIT License

JavaScript 90.27% SCSS 9.73%
photoviewer lightbox image-gallery responsive modal draggable resizable zoomable fullscreen mousewheel

photoviewer's Introduction

PhotoViewer

Travis npm license Gitter Financial Contributors on Open Collective

photoviewer

PhotoViewer is a JS plugin to view images just like in Windows.

If you want to support IE8, please goto Magnify.

Quick links

Documentation | Examples

Features

  • Vanilla JS
  • Modal draggable
  • Modal resizable
  • Modal maximizable
  • Image movable
  • Image zoomable
  • Image rotatable
  • Keyboard control
  • Fullscreen showing
  • Multiple instances
  • Browser support IE9+
  • RTL support

Installation

You can install the plugin via npm

$ npm install photoviewer --save

Quick Start

Step 1: Include files

@use 'photoviewer';
import PhotoViewer from 'photoviewer';

or

<!-- Core CSS file -->
<link href="/path/to/photoviewer.css" rel="stylesheet">

<!-- Core JS file -->
<script src="/path/to/photoviewer.js"></script>

Step 2: Initializing

The usage of photoviewer is very simple, the PhotoViewer's constructor has 2 arguments.

  1. Array with objects of image info.
  2. Options
// build images array
var items = [
    {
        src: 'path/to/image1.jpg', // path to image
        title: 'Image Caption 1' // If you skip it, there will display the original image name(image1)
    },
    {
        src: 'path/to/image2.jpg',
        title: 'Image Caption 2'
    }
];

// define options (if needed)
var options = {
    // optionName: 'option value'
    // for example:
    index: 0 // this option means you will start at first image
};

// Initialize the plugin
var photoviewer = new PhotoViewer(items, options);

Step 3: Binding Event

At last, binding click event on a button element at initializing.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

MIT License

photoviewer's People

Contributors

dependabot[bot] avatar jin2gh avatar monkeywithacupcake avatar nzbin 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

photoviewer's Issues

Problem on last image

When i open the last image, arrows (left and right) do not work and give an error on the following code:

       this.loadImg(this.groupData[index].src, function () {
          _this3._triggerHook('changed', index);
        }, function () {
          _this3._triggerHook('changed', index);
        });

Browser gives Uncaught TypeError: Cannot read property 'src' of undefined

I am using the "button way" as shown in your example and use something like:

$(document).on('click','.res img',function(){
 let a =  $(this).attr('index');
  new PhotoViewer(items, {index: a});
});

By the way it works fine with the newest jQuery version 3.4.0,

请问为什么拖动禁止不了啊

options = {
    index: $(this).index()-1,
    draggble:false,  
    resizable:false,
    movable:false,
    title:false,
    footToolbar:['zoomIn','zoomOut','prev','next','rotateRight'],
};

禁止不了拖动

Incompatible with happy-dom

Hi there! I'm using Vitest to run my tests, and for a performance boost I'm investigating rendering with happy-dom. However, when I try to run my tests, I get this error:

TypeError: Cannot set property isConnected of [object Object] which has only a getter
 ❯ new Node node_modules/happy-dom/src/nodes/node/Node.ts:57:29
 ❯ new Element node_modules/happy-dom/lib/nodes/element/Element.js:25:9
 ❯ new HTMLElement node_modules/happy-dom/lib/nodes/html-element/HTMLElement.js:17:9
 ❯ HTMLDocument.createElementNS node_modules/happy-dom/src/nodes/document/Document.ts:834:19
 ❯ HTMLDocument.createElement node_modules/happy-dom/src/nodes/document/Document.ts:803:15
 ❯ Object.<anonymous> node_modules/photoviewer/dist/photoviewer.common.js:97:22

I've seen this issue in a few libraries, including the axe-core library capricorn86/happy-dom#978 where they documented a trivial workaround.

Thanks for all your work on this library, it's awesome.

Dark mode

Hi,

First of all thanks for creating such a great plugin. I had always wanted to find something that resembles Windows photoviewer.

I have a couple of suggestion. Would you be able to introduce a dark mode that can be configured?
The other suggestion is if we can make the icons at the footer a bit bigger or make the icon and title size configurable?

Thanks

Feature Request: Preview images on bottom

Would it be possible to add a feature to list the images (thumbnails?) before and after the current (like previews) on the bottom like in the windows 10 photo viewer app?

Cannot use PhotoViewer with jquery datatable

Description

I use PhotoViewer together with jquery datatable with the expectation that the image in the datatable can be zoomed with PhotoViewer

Issue

With expectations as in the description I encountered the following problems:

Uncaught TypeError: Cannot read property 'src' of undefined
    at PhotoViewer.init (photoviewer.js:1917)
    at new PhotoViewer (photoviewer.js:1906)
    at HTMLAnchorElement.<anonymous> (<anonymous>:15:13)
    at HTMLAnchorElement.dispatch (jquery.3.2.1.min.js:3)
    at HTMLAnchorElement.q.handle (jquery.3.2.1.min.js:3)

Here are some screenshots :
image

but somehow it's work for some image
image

And this is the error one
image

RTL Bug

Hi
I use ng-matero.
In RTL mode, the Photoviewer is fixed on the right and cannot be moved with the mouse.
image

View PDF

hi, sir is there any option to view the pdf.

Any ways to add icons to custom buttons?

Tried adding the keys of the custom buttons to icons but nothing happened.

var viewer = new PhotoViewer(items, {
  index: 0,
  footerToolbar: ['zoomIn','zoomOut','prev','fullscreen','next','actualSize','rotateRight','openInNew'],
  customButtons: {
    openInNew: {
      text: "新标签打开",
      title: "新标签打开",
      click: function (context, e) {
        window.open(context.img.src);
      }
    }
  },
  icons: {
	"openInNew": "<svg t=\"1614215430739\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"4559\" width=\"16\" height=\"16\"><path d=\"M810.666667 810.666667H213.333333V213.333333h298.666667V128H213.333333a85.333333 85.333333 0 0 0-85.333333 85.333333v597.333334a85.333333 85.333333 0 0 0 85.333333 85.333333h597.333334c46.933333 0 85.333333-38.4 85.333333-85.333333v-298.666667h-85.333333v298.666667zM597.333333 128v85.333333h153.173334l-419.413334 419.413334 60.16 60.16L810.666667 273.493333V426.666667h85.333333V128h-298.666667z\" p-id=\"4560\"></path></svg>"
}});

yjuiXq.png

Option to pan images after zoom

Zoom feature becomes not much useful without being able to pan it. Would be awesome if you could provide it in future. Thanks!

pinch and zoom in mobile is not functional

Unfortunately pinch and zoom in mobile is not functional, how come it can zoom in & out with scroll but not in mobile?
Move is not working neither in mobile unfortunately

With pagination, Photoviewer is getting initialized multiple times, hence opens multiple instance of photoviewer.

I am binding images with pagination on demand call. Hence, after each page change I need to initialize photoviewer with new set of items. It looks like, after loading items on different page and initializing photoviewer, new instance of photoviewer gets initialized as well as previous instance also exists. This opens multiple instance of same image in photoviewer on clicking once on image.

I think, on initializing again, there should be an option to destroy old instance or there should be a way to update items in existing instance.

Capture

Multiple Instances

Please could you tell me how to add multiple instances of photoviewer?
I can get it to work by duplicating the initialize script and changing the data-gallery name:
$('[data-gallery=photoviewer]')
$('[data-gallery=photoviewer2]')
However the site I am building will have hundreds of galleries that will be dynamically created so this is not an option.
Is there a way to restart the script if the links are within a parent div?
Any help will be greatly appreciated as I would love to use your amazing lightbox.
Many thanks
John

Arrows Prev and Next

photoviewer-button photoviewer-button-prev
AND
photoviewer-button photoviewer-button-next are not working for me can you please solve this issus in js

photoviewer error while compiling angular

I am trying to run an angular project which has the dependency photoviewer, It used to work and recently I'm getting this error while compiling the angular project

`ERROR in ./node_modules/photoviewer/src/js/core.js 35:19
Module parse failed: Unexpected token (35:19)
File was processed with these loaders:

  • ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js
    You may need an additional loader to handle the result of these loaders.
    | class PhotoViewer {
    | // Store modal instances

static instances = [];
|
| // Whether modal opened
`

I tried upgrading/downgrading the version, nothing helped, Can someone please help on this?

TIA!

replace `data-src` but can not show the photo

Hi nzbin,

Thanks for sharing.

I have meet a problem in steps2.

Way 2: Initializing as jQuery plugin

1.Using DOM structure is OK.

  1. I want use this way:

<img data-gallery="jquery" data-src="big-1.jpg" src="small-1.jpg">

I have replace data-src and src with same jpeg, but I can see picture, click photo can not see it. Can you help me fix it?

Pls help check attached photo for details.

Thanks.

image

error handling

How do I show an error if the image is no longer there?

[Behavior] Image not centered while maximized or zoomed in.

Hi, thanks @nzbin for this great plugin.

I have submitted this issue for [Behavior] only.

Clicking on image and popup display is correct,
but when zoomed out OR maximized, image is fixed floated to right edge, not centered.
(Works correctly outside of <body> )
please help me out, or suggest override styling.

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.