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.

  • 8.0.0
  • latest
  • 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.

Demo

npm version npm downloads software license
build status coverage status


example



Installation

Install the package via npm:

npm install --save zoom.ts

Usage

The example directory contains the code used to demonstrate an application with zoom.ts installed.

Static Site

To integrate zoom.ts into a static site, import the UMD module and interface with the library via the global window.zoom. The snippet below demonstrates linking the bundle (dist/zoom.js) and the stylesheet (dist/zoom.css). It then calls the listen function to add an event listener to the document.body when the page is ready.

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="dist/zoom.css">
    <script type="text/javascript" src="dist/zoom.js"></script>
    <script>window.zoom.listen();</script>
  </head>

  <body>
    <img
      class="zoom__image"
      src="tower.jpeg"
      data-width="2048"
      data-height="1366"
      data-src="tower-full.jpeg"
    />
  </body>
</html>

Application

To integrate zoom.ts into a web application, follow the steps outlined below:

  1. Detect and store the Features of the document.body.style
  2. Locate the element you wish to make zoomable
  3. Register a ZoomListener on the target image
  4. In the listener's callback, create and store a Zoom instance
  5. Call expand on the Zoom instance to begin zooming the image
  6. If the user navigates to a different page in the application, call destroy on the Zoom instance

The snippet below demonstrates finding the first element with the zoom__image class and adding a ZoomListener to any click events it fires. When fired, the event listener will create a Zoom instance and store it as a variable named zoom, then immediately expand the image. After 5 seconds have passed, the zoom will be forcefully removed via the call to destroy.

import { Features, Zoom, ZoomDOM, ZoomListener } from 'zoom.ts';

let features = Features.of(document.body.style); // (1)
let image = document.querySelector('.zoom__image'); // (2)

image.addEventListener('click', new ZoomListener((dom) => { // (3)
    let zoom = new Zoom(dom, features); // (4)
    
    zoom.expand(); // (5)
    
    setTimeout(() => {
        zoom.destroy(); // (6)
    }, 5000);
}));

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 17 Mar 2018

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