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

modularload

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modularload

Dead simple page transitions and lazy loading.

  • 1.2.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by11.76%
Maintainers
2
Weekly downloads
 
Created
Source

modularLoad

Dead simple page transitions and lazy loading.

Installation

npm install modularload

Why

  • Simple
  • Lightweight
  • Minimal configuration
  • No dependencies

Usage

import modularLoad from 'modularload';

this.load = new modularLoad({
    enterDelay: 300
});
<div data-load-container>
    <h1>Hello</h1>
    <a href="/blog">Read more</a>
</div>
With custom transitions
import modularLoad from 'modularload';

this.load = new modularLoad({
    enterDelay: 300,
    transitions: {
        transitionName: {
            enterDelay: 450
        },
        transitionTwoName: {
            enterDelay: 600
        }
    }
});
<html data-page="home">
   <body> 
        <nav>
            <a href="/contact" data-load="transitionName">Contact</a>
        </nav>
        <div data-load-container>
            <h1>Hello</h1>
            <a href="/blog" data-load="transitionTwoName">Read more</a>
        </div>
   </body>
</html> 
With custom container
import modularLoad from 'modularload';

this.load = new modularLoad({
    enterDelay: 600,
    transitions: {
        article: {
            enterDelay: 300
        }
    }
});
<div data-load-container>
    <div data-load-container="article">
        <h1>Article One</h1>
        <p>Text</p>  
    </div>
    <a href="/blog/article-one" data-load="article">Article One</a> 
    <a href="/blog/article-two" data-load="article">Article Two</a> 
</div>
With lazy images
import modularLoad from 'modularload';

this.load = new modularLoad();
<div data-load-container>
    <header data-load-style="background-image: url('images/header.jpg');">
        <h1>Hello</h1>
    </header>
    <main>
        <img data-load-src="images/img.jpg">
        <a href="/blog">Read more</a>
    </main>
</div> 
With events
import modularLoad from 'modularload';

this.load = new modularLoad();

this.load.on('loaded', (transition, oldContainer, newContainer) => {
    console.log('👌');

    if (transition == 'transitionName') {
        console.log('🤙');
    }
});
With methods
import modularLoad from 'modularload';

this.load = new modularLoad();

this.load.goTo('/page', 'transitionName');

Options

OptionTypeDefaultDescription
namestring'load'Data attributes name
loadingClassstring'is-loading'Class when a link is clicked.
loadedClassstring'is-loaded'Class when the new container enters.
readyClassstring'is-ready'Class when the old container exits.
transitionsPrefixstring'is-'Custom transitions class prefix.
transitionsHistorybooleantrueRedo the custom transitions while using the back button.
enterDelaynumber0Minimum delay before the new container enters.
exitDelaynumber0Delay before the old container exists after the new enters.
loadedDelaynumber0Delay before adding the loaded class. For example, to wait for your JS DOM updates.
transitionsobject{}Custom transitions options.

Attributes

AttributeValuesDescription
data-load-container , stringContainer you want to load with optional string.
data-loadstring, falseTransition name or disable transition.
data-load-urlbooleanUpdate url without loading container.
data-load-srcstringLazy load src attribute.
data-load-srcsetstringLazy load srcset attribute.
data-load-stylestringLazy load style attribute.
data-load-hrefstringLazy load href attribute.

Events

EventArgumentsDescription
loadingtransition, oldContainerOn link click.
loadedtransition, oldContainer, newContainerOn new container enter.
readytransition, newContainerOn old container exit.
imagesOn all images load.

Methods

MethodDescription
goTo('href'[, 'transition'][, true])Go to href. With optional transition name and boolean for url update only.

FAQs

Package last updated on 24 Aug 2021

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