2.5.5 • Published 6 years ago

@wearejust/transition v2.5.5

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

Transition

Easily add transitions between pages. Either use the built in types like fade or slide, or add your own custom transition.

Installation

npm install @wearejust/transition --save

Usage

var Transition = require('@wearejust/transition');

Options

Transition will initialize automatically, but if you want to change any of it's options, use the init method.

Transition.init({
    defaultTarget: '#container'
});
KeyValuesDefaultDescription
defaultTargetstring, nullnullDefault target. Null uses the body
defaultTypestringfadeDefault transition type
errorstring, functionreloadError callback. Use 'reload' to reload the page or call your own function
excludestring, nullnullItems to exclude from parsing. Can also use 'no-transition' class
lazyLoadstring, nullsource,iframeRemoves sources in loaded data and restores after the transition
parseOnInitbooleantrueParse document for items on init

Targets

Changes the contents of the target, instead of the whole body.

 <a data-transition-target="yourtarget"></a>
 <div data-transition-id="yourtarget"></div>

Transition types

There are several transition types built in. The default fade can be changed in the options.

NameDescription
fadeFade out old, fade in new
slideSame as slide-left
slide-leftPlace new content on the right and slide to the left
slide-rightPlace new content on the left and slide to the right

Every item can have it's own transition type with a data atribute.

<a href="" data-transition-type="fade">Fade</a>
<a href="" data-transition-type="slide">Slide</a>

Adding custom type 'yourtype':

<a href="" data-transition-type="yourtype"></a>
Transition.types.yourtype = {
    replace: true,                          // Replaces the content after load. Set to false to use previous content in transition, like when sliding
    scrollToTop: true,                      // Scrolls to the top after placing the content
    before: function(target, callback) {    // Before starting
        callback();                         // Call once done to continue to start
    },
    start: function(target, callback) {     // Before loading
        callback();                         // Call once done to continue to load
    },
    place: function(target, content) {     // Custom placing of the content, default is null
        
    },
    end: function(target, callback) {       // After loading
        callback();                         // Call once done to continue to after
    },
    after: function(target, callback) {     // After end
        callback();                         // Call once done to complete
    }
};

Events

Events are triggered on every step during the transition. Use the on method to trigger an event handler.

Transition.on('ready', function() {
    // Do something after initializing or loading a new page
});

Available events, in order in which they are triggered.

NameParametersDescription
unavailableHistory API is not available, transitions disabled
availableHistory API is available, transitions enabled
readyReady, after initializing
changeurlLocation has changed (using popState)
beforeBefore the start transition
startStart transition
loadLoad page
loadeddataPage is loaded
placedcontentContent of the loaded page is placed in the DOM
endEnd transition
afterAfter the end transition
parseitemsAfter parsing new content for items
completeCompleted transition

Keyboard events

Binds keys to items. If a bound key is pressed, that item will be triggered.

 <a data-transition-key="27">Close</a>
 <a data-transition-key="37">Previous</a>
 <a data-transition-key="39">Next</a>

Properties

Transition

NameTypeDescription
availablebooleanHistory API availability
changingbooleanSet to true before animating, to false when done
currentItemobjectThe current clicked item
currentTypeobjectThe current transition type
fromstringPrevious location.href
locationstringCurrent location.href
itemsarrayList of all items on the page
optionsobjectOptions of Transition
typesobjectCollection of all transition types

Transition.currentItem

NameTypeDescription
bodyClassstringClass attribute of the loaded body
elementjQuery objectDOM element
fromstringPrevious location.href
targetjQuery objectTarget container
targetIsBodybooleanIf target container is the body
typestringTransition type
urlstringDOM element href
2.5.5

6 years ago

2.5.4

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.7

7 years ago

2.1.6

7 years ago

2.1.5

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago