Viewer.js is a robust JavaScript image viewer designed for web applications, currently stable at version 1.11.7. It provides a rich set of features including modal and inline viewing modes, touch gesture support, image movement, zooming, rotation, scaling (flipping), and comprehensive keyboard navigation. The library is actively maintained with frequent minor releases focusing on bug fixes and compatibility improvements. Key differentiators include its extensive API with 53 options, 23 methods, and 17 events, offering fine-grained control over the viewing experience. It ships with TypeScript type definitions, making it suitable for modern TypeScript projects, and offers various build formats (UMD, CommonJS, ES Module) to fit different project setups. While a jQuery wrapper exists, the core library is standalone and dependency-free.
npm install viewerjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Viewer.js for both a single image and a gallery of images. It shows importing the necessary CSS and the `Viewer` class, setting up basic options like `inline` mode, and utilizing event callbacks such as `viewed`.
Ensure `import 'viewerjs/dist/viewer.css';` is included in your application's entry point, or `<link href="/path/to/viewer.css" rel="stylesheet">` is present in your HTML `<head>`.
For specific images within a larger structure, create a distinct wrapper element for the target images or initialize `Viewer` on each `<img>` element directly.
If keyboard control is required, use Viewer.js in its default modal display mode. For inline viewers, implement custom controls if keyboard accessibility is a strict requirement.
Set the `url` option in the Viewer constructor, for example: `new Viewer(element, { url: 'data-original-src' });` or `url(image) { return image.dataset.originalSrc; }`.Ensure you have `import Viewer from 'viewerjs';` at the top of your JavaScript file, or that the `<script src="/path/to/viewer.js"></script>` tag is present and correctly placed in your HTML.
Verify the element ID or selector is correct. Wrap your initialization code in a `DOMContentLoaded` listener: `document.addEventListener('DOMContentLoaded', () => { new Viewer(...); });`.Add `import 'viewerjs/dist/viewer.css';` to your main JavaScript file (if using a bundler) or include `<link href="/path/to/viewer.css" rel="stylesheet">` in your HTML's `<head>` section, ensuring the path is correct.
No dependency data recorded yet.