Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zoom.ts

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zoom.ts

A lightweight TypeScript library for image zooming, as seen on Medium.

  • 6.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-41.67%
Maintainers
1
Weekly downloads
 
Created
Source

zoom.ts

A lightweight TypeScript library for image zooming, as seen on Medium.

A running demonstration can be found here.

license npm version npm downloads dependencies status devDependencies status

zoom.ts easily plugs into your application and starts listening to zoom events as soon as the DOM is ready. The library accounts for just 4.2kB of bandwidth once gzipped and requires no external bootstrapping.

Holding either the or Ctrl key will open the image in a new tab when clicked. Zoomed images can be dismissed either by clicking the image, scrolling away, or pressing Esc.

Installation

Install the package via npm:

npm install --save zoom.ts

Then you can either link the JavaScript distribution file to have zoom.ts listen on your webpage, or you can configure and include the library itself your existing application.

To include and configure the library yourself, you will need to first @import the stylesheet. Remember to define any overrides before importing the stylesheet, for example:

$zoom-overlay-background-color: blue; // change overlay background to blue
$zoom-transition-duration: 1000; // slow down the transitions

@import '~zoom.ts/style';

Next you will need to import the library itself. In the example below, the ready function will apply a callback as soon as the DOM has loaded, and calling listener.start() will add an event listener to the DOM that will respond to clicks on images marked as zoomable.

import { ready } from 'zoom.ts/lib/Document';
import { Listener } from 'zoom.ts/lib/Listener';

let listener: Listener = new Listener();

ready(() => {
    listener.start();
    console.log('zoom.ts started listening for click events...');
});

Usage

  1. Add the class zoom__element to your <img>.
  2. Wrap your <img> in a div with a class of zoom (i.e. <div class="zoom">)
  3. A width and height can be configured to specify the dimensions that the expanded image should size to by add the data-width and data-height attributes to the wrapper div.
  4. The loading of a big image can be deferred by adding the data-src attribute to the wrapper div.
<!DOCTYPE html>
<html>
  <body>
    <div class="zoom" data-width="3500" data-height="2333" data-src="img/forest-full.jpg">
      <img class="zoom__element" src="img/forest.jpg">
    </div>

    <script type="text/javascript" src="dist/zoom.js"></script>
  </body>
</html>

Building

The following scripts are configured to run via npm:

  • npm start
  • npm run build
    • Builds the distribution and places it under the ./dist directory.
  • npm run dist
    • Builds, minifies, and optimizes the distribution and places it under the ./dist directory.
  • npm run clean
    • Cleans the ./dist directory.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

This project is available under the terms of the ISC license. See the LICENSE file for the copyright information and licensing terms.

Keywords

FAQs

Package last updated on 24 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc