0.0.14 • Published 1 year ago

@xlibz/image v0.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

image

Something similar to the <picture> tag but with a cleaner and clearer syntax

Example

<x-image
  lazy
  srcset="
    /hello.1024max.jpg,
    /hello.1024max.webp,
    /hello.1025min.jpg,
    /hello.1025min.webp,
    /hello.1025min.2x.webp,
    /hello.1025min.2x.jpg,
  "
>
</x-image>

Attributes

  • srcset: an array of strings, where each string represents an image URL.

    The order of specifying URLs is not important. It is determined automatically by the library.

    You can write the URL in the following ways:

    • /[name].[extension]
    • /[name].[px]max.[extension]
    • /[name].[px]min.[extension]
    • /[name].[px]min.[density]x.[extension]
    • /[name].[px]max.[density]x.[extension]
    • /[name].[density]x.[extension]
  • lazy: Lazy loading image (using IntersectionObserver)

Classes

  • .loading: added to the <x-image> element when the image starts loading.
  • .loaded: added to the <x-image> element when the image is loaded.

Recipes

  • To display a spinner while the image is loading, you can do the following:

    <x-image
      lazy
      class="image"
      srcset="/hello.jpg"
    >
      <div class="spinner"></div>
    </x-image>
    .loading .spinner {
      animation: spin 2s infinite;
    }
    
    .loaded .spinner {
      animation: unset;
      display: none;
    }
  • If you have a modal window with images inside, you can add the lazy attribute to prevent the images from loading until the modal window has a display value other than none.

Cautions

  • The library is not in its final stage, so avoid using it if you're not familiar with its functionality.

  • In the current version, you can specify any image format, but the browser compatibility check and fallback will only apply to webp format.

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

1 year ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago