npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alain_tran/loupejs

v1.1.4

Published

Create zoom on image

Downloads

322

Readme

## Usage

### Step 1: Import the Loupe

In your JavaScript file, import the `Loupe` from the package:

```javascript
import Loupe from '@alain_tran/loupejs';

Step 2: Prepare the HTML Structure

Ensure that your HTML contains the necessary elements with appropriate data-target attributes:

<div class="relative w-96 h-96 cursor-none">
  <img src="/path-to-background-image.jpg" alt="Image à zoomer" data-target="image" class="w-full h-full object-cover">
  <div class="z-10 absolute inset-0 w-full h-full opacity-0 bg-no-repeat pointer-events-none transition-opacity duration-300" data-target="magnifier"></div>
  <div class="z-20 absolute w-20 h-20 opacity-0 bg-white/60 transition-opacity duration-300 pointer-events-none" data-target="lens"></div>
</div>
  • data-target="image": The image you want to apply the magnifier effect to.
  • data-target="magnifier": The magnifier element, which will display the zoomed-in portion of the image.
  • data-target="lens": The lens element, which will move with the cursor to indicate the zoomed area.

Step 3: Initialize the Loupe

Once the DOM is loaded, you need to initialize the Loupe with the corresponding elements:

document.addEventListener('DOMContentLoaded', () => {
  const imageElement = document.querySelector('[data-target="image"]');
  const magnifierElement = document.querySelector('[data-target="magnifier"]');
  const lensElement = document.querySelector('[data-target="lens"]');

  if (imageElement && magnifierElement && lensElement) {
    new Loupe(imageElement, magnifierElement, lensElement);
  }
});

Step 4: Customize the Magnifier (Optional)

You can customize the zoom level and background image by passing additional parameters to the Loupe:

new Loupe(imageElement, magnifierElement, lensElement, 'path-to-background-image.jpg', 4);
  • backgroundUrl: (Optional) The URL of the image to use for the background of the magnifier.
  • zoomLevel: (Optional) The zoom level, where the default is 3.

Step 5: Add Styling

You can add additional styles to the magnifier and lens elements as needed. For example:

[data-target="magnifier"] {
  border-radius: 50%;
  border: 2px solid #000;
  background-repeat: no-repeat;
  background-position: 0 0;
}

[data-target="lens"] {
  border-radius: 50%;
}

Step 6: Run Your Project

After following these steps, your image should have a functional magnifier effect when hovered over.

Example

Here is a basic example to see the package in action:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Magnifier Example</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div style="position: relative;">
    <img src="your-image.jpg" data-target="image" alt="Zoomable Image" style="width: 100%; height: auto;">
    <div data-target="magnifier" class="opacity-0" style="position: absolute; width: 100px; height: 100px; pointer-events: none;"></div>
    <div data-target="lens" class="opacity-0" style="position: absolute; width: 50px; height: 50px; border: 2px solid #000;"></div>
  </div>

  <script type="module">
    document.addEventListener('DOMContentLoaded', () => {
      const imageElement = document.querySelector('[data-target="image"]');
      const magnifierElement = document.querySelector('[data-target="magnifier"]');
      const lensElement = document.querySelector('[data-target="lens"]');

      if (imageElement && magnifierElement && lensElement) {
        new Loupe(imageElement, magnifierElement, lensElement);
      }
    });
  </script>
</body>
</html>

License

This package is open-source and available under the MIT License.