1.2.8 • Published 3 years ago

modularload v1.2.8

Weekly downloads
39
License
MIT
Repository
github
Last release
3 years ago

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.
1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

4 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago