• This repository has been archived on 06/Feb/2023
  • Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] Complete, flexible, easy to use page transition library - swup extension.

swupjs

WARNING: this repository is deprecated in favour of JS-plugin

Swupjs is an extension of swup, which modifies the module for use with JavaScript animations.

Swupjs only slightly modifies swup, where all the capabilities of swup remain the same, with only one exception - timing and animations are based on JavaScript, not CSS transitions. For more information about functionality and idea of swupjs, refer to swup documentation.

Installation

npm install swupjs

or include the file from the dist folder

<script src="./dist/swupjs.js"></script>

How it works

Swupjs is enabled similarly as swup.

let options = {}
const swupjs = new Swupjs(options)

Animations option

To use your animations for page transitions, you first need to define the animation object.

animations: {
    '*': {
        out: function (next) {
            next()
        },
        in: function (next) {
            next()
        }
    }
}

The example above is the default setup in swupjs and defines two animations, where out is the animation (function) being executed before content replace, and in is animation being executed after the content is replaced. As one may have noticed, one parameter is passed into both functions. Call of next function serves as an indicator, that animation is done - so in a real world next() would be called as a callback of the animation. As you can see, by default no animation is being executed and next() is called right away.

Note: Although the whole purpose of swup is to enable page transitions, this can still enhance your user experience even without the animation as it can shorten your load time drastically when preload and/or cache options are set to true. In most cases, your page change should be immediate without any wait time.

out: function (next) {
    setTimeout(next, 2000)
}

In the example above, next function is called after two seconds, which means that swupjs would wait two seconds (or any time necessary for the load of the new page content), before continuing to the content replace.

Animation object needs to be passed as a part of your options.

let options = {
    animations: {
        '*': {
            out: function (next) {
                next()
            },
            in: function (next) {
                next()
            }
        }
    }
}
const swupjs = new Swupjs(options)

Basic usage with tools like GSAP would look something like the following:

let options = {
    animations: {
        '*': {
            in: function(next){
                document.querySelector('#swup').style.opacity = 0;
                TweenLite.to(document.querySelector('#swup'), .5, {
                    opacity: 1,
                    onComplete: next
                });
            },
            out: function(next){
                document.querySelector('#swup').style.opacity = 1;
                TweenLite.to(document.querySelector('#swup'), .5, {
                    opacity: 0,
                    onComplete: next
                });
            }
        },
    }
}

const swupjs = new Swupjs(options);

Choosing the animation

As one may have noticed, the name of animation object in options is defined as '*', which serves as a fallback or base set of animations used throughout the website. Custom animations can be defined for a transition between any pages, where the name is defined by [starting route]>[final route].

...
'homepage>documentation': {
    out: function (next) {
        next()
    },
    in: function (next) {
        next()
    }
}
...

The animation above would be executed for the transition between homepage (/) and documentation page (/documentation). Notice that for the lack of route, keyword "homepage" is used. Any of the two routes can also be defined by wildcard symbol (homepage>* or *>documentation). The most fitting animation is always chosen.

Custom animation to dynamic pages

Similarly to swup, where data-swup-transition attribute of the clicked link is used for assigning a special class to the html tag, swupjs uses the same attribute for choosing custom animation. In case the attribute is defined on clicked link, swupjs also tests the animation object for the content of the data attribute. So following attribute data-swup-transition="post" would end up in *>post being executed.

...
    '*': {
       ...
    },
    '*>documentation': {
       ...
    },
    '*>post': {
       ...
    }
...

More Repositories

1

swup

Versatile and extensible page transition library for server-rendered websites 🎉
TypeScript
4,619
star
2

astro

Astro integration for swup 🚀
TypeScript
89
star
3

js-plugin

A swup plugin for managing animations in JS  🎸
TypeScript
23
star
4

fragment-plugin

A swup plugin for dynamically replacing containers based on rules 🧩
TypeScript
15
star
5

preload-plugin

A swup plugin for preloading pages to speed up navigation 🚀
TypeScript
13
star
6

docs

Official swup documentation 📘
JavaScript
12
star
7

swup-gia-demo

Demo of swup and gia ⚡️
HTML
7
star
8

parallel-plugin

A swup plugin for animating the previous and next page in parallel  🎏
TypeScript
6
star
9

head-plugin

A swup plugin for updating the contents of the head tag 🐶
TypeScript
5
star
10

overlay-theme

A swup theme for showing an overlay during animations 🎨
CSS
5
star
11

swupjs-gia-demo

Demo of swup with JS plugin and gia ⚡️
HTML
5
star
12

livewire-plugin

A swup plugin for integrating Laravel Livewire ♻️
JavaScript
5
star
13

cli

Create swup plugins and themes in seconds, or validate your website 🚤
TypeScript
5
star
14

slide-theme

A swup theme for slide and fade animations 🎨
CSS
4
star
15

forms-plugin

A swup plugin for submitting forms 📋
TypeScript
4
star
16

body-class-plugin

A swup plugin for updating the body classname 🎊
TypeScript
4
star
17

progress-plugin

A swup plugin for displaying a progress bar ⏳
TypeScript
4
star
18

a11y-plugin

A swup plugin for enhanced accessibility 🔉
TypeScript
4
star
19

scripts-plugin

A swup plugin for re-evaluating scripts ♻️
TypeScript
4
star
20

scroll-plugin

A swup plugin for smooth scrolling 🏄‍♂️
TypeScript
3
star
21

route-name-plugin

A swup plugin for named routes and route-based animation 🧭
TypeScript
2
star
22

plugin

Base class for creating swup plugins 📁
TypeScript
2
star
23

plugin-template

Template for swup plugins 🎁
JavaScript
2
star
24

gia-plugin

A swup plugin for integrating Gia frontend components 🏭
JavaScript
2
star
25

fade-theme

A swup theme for fade animations 🎨
JavaScript
1
star
26

webpack-config

Webpack config for swup packages 🛠️
JavaScript
1
star
27

prettier-config

Prettier config for swup packages 🛠️
JavaScript
1
star
28

matomo-plugin

A swup plugin for integrating Matomo analytics 📈
TypeScript
1
star
29

offline-plugin

A swup plugin for making your site available when offline ⛈️
TypeScript
1
star
30

ga-plugin

A swup plugin for integrating Google Analytics 📈
JavaScript
1
star
31

.github

1
star