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

vuepress-plugin-img-lazy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuepress-plugin-img-lazy

a vuepress plugin to better supporting image lazy loading

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vuepress-plugin-img-lazy

a vuepress plugin to better supporting image lazy loading

The plugin will preferentially use native image lazy-loading, if the browser does not support it, it will be implemented through IntersectionObserver

base on markdown-it-img-lazy and markdown-it-imsize

Live Demo and Documentation


Installation

yarn add vuepress-plugin-img-lazy
# or
npm i vuepress-plugin-img-lazy

Usage

module.exports = {
  plugins: [
    'img-lazy'
  ]
}
![img](/img.jpg)
# or
![img](/img.jpg =500x300) <!-- better -->

Use in theme

  • registered as global components
// enhanceAppFile.js
import ImgLazy from 'vuepress-plugin-img-lazy/ImgLazy'

export default ({ Vue }) => {
  Vue.component(ImgLazy.name, ImgLazy)
}
  • or registered as components
import ImgLazy from 'vuepress-plugin-img-lazy/ImgLazy'

export default {
  components: { ImgLazy }
}
  • use
<template>
  <img-lazy src="/img.jpg" />
</template>

If you registered as global components, you can use it directly in the markdown file

<img-lazy src="/img.jpg" />

Options

useNative

  • Type: Boolben
  • Default: true
  • Required: false

Use the native image lazy-loading for the web

selector

  • Type: string
  • Default: lazy
  • Required: false

Default class name for image

rootMargin

  • Type: String
  • Default: 200px
  • Required: false

rootMargin for IntersectionObserver

prefix

  • Type: string Function
  • Default: src => src && src.charAt(0) === '/' && !src.startsWith(ctx.base) ? ctx.base + src.slice(1) : src
  • Required: false

Config prefix for src in images

Other

  1. Base URL already included by default, But it does not include the <img/> label in the markdown file

If you need to use both Base URL and <img/> labels, refer to

<img :data-src="$withBase('/img.png')" loading="lazy" class="lazy">
  1. In order to better supporting image lazy loading, it is better to specify the size of the image (in some themes, you need to set display as inline block or block separately), so as to ensure that the image can occupy the position it should occupy

Keywords

FAQs

Package last updated on 09 Jul 2020

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