Socket
Socket
Sign inDemoInstall

imgset

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    imgset

Javascript image loading based on element width.


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
824 kB
Created
Weekly downloads
 

Readme

Source

Imgset.js

Javascript image loading based on element width.

Syntax

Note: alt, and focus are not currently implemented.

// HTML
<span class="Imgset">
  <noscript 
    data-json='{
      "set": {
        "0": "photo-500.jpg",
        "768": "photo-1000.jpg",
        "1024": "photo-1400.jpg"
      },
      "alt": "Alternate text.",
      "focus": ["x", "y"]
    }'
  >
    <img src="photo-1000.jpg" alt="Alternate Text." />
  </noscript>
</span>

In most of my implementations I know the image width and height and inline padding bottom (height / width * 100%) to preserve the image ratio.

<span class="Imgset" style="padding-bottom: 66.66%;">
  ...
</span>
<span class="Imgset">
  // Elements created by Imgset.js:
  <div class="Imgset__background" background-image="{ img_source }" />
  <img class="Imgset__img" src="{ img_source }" />
  <noscript 
    data-json='{...}'
  >
    <img src="photo-1000.jpg" alt="Alternate Text." />
  </noscript>
</span>

Do some scripts

// JS
import Imgset

Imgset()
// or
Imgset('.mySelector')

FAQs

Last updated on 26 Nov 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc