Convert Figma logo to code with AI

barbajs logobarba

Create badass, fluid and smooth transitions between your website’s pages

11,577
477
11,577
10

Top Related Projects

πŸ›€ Detection of elements in viewport & smooth scrolling with parallax.

Turbolinks makes navigating your web application faster

4,604

Versatile and extensible page transition library for server-rendered websites πŸŽ‰

6,701

The speed of a single-page web application without having to write any JavaScript

A lightweight script to animate scrolling to anchor links.

3,068

The most versatile JavaScript typewriter effect library on the planet.

Quick Overview

Barba.js is a small and flexible JavaScript library that helps create fluid and smooth transitions between your website's pages. It reduces the delay between user actions and website responses, making navigation feel faster and more seamless. Barba.js works by preventing the default browser page load and using AJAX to fetch new content.

Pros

  • Improves perceived loading times and creates a smoother user experience
  • Easy to integrate with existing projects and works with any back-end language
  • Highly customizable with hooks and events for fine-grained control
  • Lightweight and has no dependencies

Cons

  • Requires JavaScript to function, which may impact SEO if not implemented correctly
  • Can be complex to set up for more advanced transitions and animations
  • May require additional work to handle browser history and deep linking
  • Not suitable for all types of websites, especially those with complex server-side rendering

Code Examples

  1. Basic usage:
import barba from '@barba/core';

barba.init();

This code initializes Barba.js with default settings.

  1. Custom transition:
import barba from '@barba/core';

barba.init({
  transitions: [{
    name: 'opacity-transition',
    leave(data) {
      return gsap.to(data.current.container, {
        opacity: 0
      });
    },
    enter(data) {
      return gsap.from(data.next.container, {
        opacity: 0
      });
    }
  }]
});

This example defines a custom transition using GSAP for animation.

  1. Hooks usage:
import barba from '@barba/core';

barba.hooks.beforeEnter(() => {
  // Do something before entering a new page
});

barba.hooks.after(() => {
  // Do something after the transition is complete
});

This code demonstrates how to use Barba.js hooks to execute custom logic during transitions.

Getting Started

To get started with Barba.js:

  1. Install the library:

    npm install @barba/core
    
  2. Import and initialize Barba in your JavaScript file:

    import barba from '@barba/core';
    
    barba.init();
    
  3. Wrap your main content in a data-barba="wrapper" element and each page's content in a data-barba="container" element:

    <div data-barba="wrapper">
      <div data-barba="container">
        <!-- Your page content here -->
      </div>
    </div>
    
  4. Customize transitions and add hooks as needed for your specific use case.

Competitor Comparisons

πŸ›€ Detection of elements in viewport & smooth scrolling with parallax.

Pros of Locomotive Scroll

  • Focuses specifically on smooth scrolling and parallax effects
  • Provides advanced scroll-based animations and transformations
  • Offers easy integration with existing projects

Cons of Locomotive Scroll

  • Limited to scroll-based interactions, unlike Barba's page transitions
  • May have a steeper learning curve for complex animations
  • Potentially heavier performance impact on larger pages

Code Comparison

Locomotive Scroll:

import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true
});

Barba:

import barba from '@barba/core';

barba.init({
  transitions: [{
    name: 'opacity-transition',
    leave(data) { /* ... */ },
    enter(data) { /* ... */ }
  }]
});

Locomotive Scroll excels in creating smooth, parallax scrolling experiences, while Barba focuses on seamless page transitions. Locomotive Scroll is ideal for single-page websites with complex scroll animations, whereas Barba shines in multi-page applications requiring smooth navigation between pages. The code examples demonstrate the different focus areas: Locomotive Scroll initializes a smooth scrolling container, while Barba sets up page transition animations.

Turbolinks makes navigating your web application faster

Pros of Turbolinks

  • Simpler integration, especially for Ruby on Rails applications
  • Automatic handling of browser history and URL changes
  • Smaller file size and potentially faster initial load times

Cons of Turbolinks

  • Less flexible for complex transitions and animations
  • Can be more challenging to implement custom behaviors
  • May require additional configuration for non-Rails projects

Code Comparison

Turbolinks:

document.addEventListener("turbolinks:load", function() {
  // Your JavaScript code here
});

Barba:

barba.init({
  transitions: [{
    leave(data) {
      // Transition logic
    },
    enter(data) {
      // Transition logic
    }
  }]
});

Key Differences

  • Barba offers more granular control over transitions and animations
  • Turbolinks focuses on speed and simplicity, while Barba emphasizes customization
  • Barba provides a more framework-agnostic approach, making it easier to integrate with various project types
  • Turbolinks is tightly integrated with Rails, offering out-of-the-box functionality for Rails applications
  • Barba allows for more complex page transitions and state management between views

Both libraries aim to improve the user experience by providing smoother page transitions, but they cater to different use cases and development preferences. Choose based on your project requirements and desired level of customization.

4,604

Versatile and extensible page transition library for server-rendered websites πŸŽ‰

Pros of swup

  • Smaller bundle size (around 9KB gzipped)
  • Simpler API and easier to set up for basic use cases
  • Built-in support for CSS transitions without additional plugins

Cons of swup

  • Less flexible for complex animations and transitions
  • Fewer built-in features and plugins compared to Barba
  • Limited support for custom caching strategies

Code Comparison

swup:

import Swup from 'swup';

const swup = new Swup();

Barba:

import barba from '@barba/core';

barba.init({
  transitions: [{
    leave(data) {
      // Animation logic
    },
    enter(data) {
      // Animation logic
    }
  }]
});

Key Differences

  • swup focuses on simplicity and ease of use, while Barba offers more advanced features and customization options
  • Barba provides a more robust plugin ecosystem and supports complex page transitions
  • swup has a smaller learning curve but may be limited for intricate animation requirements
  • Barba offers more granular control over the page transition process, including hooks for before, after, and during transitions

Both libraries aim to enhance user experience by providing smooth page transitions in single-page applications, but they cater to different levels of complexity and customization needs.

6,701

The speed of a single-page web application without having to write any JavaScript

Pros of Turbo

  • Integrated with Ruby on Rails ecosystem, offering seamless integration for Rails developers
  • Supports real-time updates through Turbo Streams, enabling live page updates without full reloads
  • Includes Turbo Drive for accelerating navigation and form submissions out of the box

Cons of Turbo

  • Less flexible for non-Rails projects or custom JavaScript frameworks
  • Steeper learning curve for developers not familiar with the Hotwire stack
  • Limited animation capabilities compared to Barba's transition system

Code Comparison

Turbo (basic usage):

import { Turbo } from "@hotwired/turbo-rails"
Turbo.start()

Barba (basic usage):

import barba from '@barba/core';

barba.init({
  transitions: [{
    leave(data) {
      // Transition logic
    },
    enter(data) {
      // Transition logic
    }
  }]
});

Key Differences

  • Turbo focuses on enhancing traditional server-rendered applications, while Barba is more suited for creating SPA-like experiences
  • Barba offers more granular control over page transitions and animations
  • Turbo provides a more comprehensive solution for Rails applications, including form handling and real-time updates

A lightweight script to animate scrolling to anchor links.

Pros of smooth-scroll

  • Lightweight and focused solely on smooth scrolling functionality
  • Easy to implement with minimal configuration required
  • Supports various browsers and fallbacks for older ones

Cons of smooth-scroll

  • Limited to scrolling functionality, lacking page transition features
  • Doesn't provide advanced animation or transition effects
  • May require additional libraries for more complex website interactions

Code Comparison

smooth-scroll:

var scroll = new SmoothScroll('a[href*="#"]', {
    speed: 500,
    easing: 'easeInOutCubic'
});

Barba:

barba.init({
    transitions: [{
        leave(data) {
            return gsap.to(data.current.container, {
                opacity: 0
            });
        },
        enter(data) {
            return gsap.from(data.next.container, {
                opacity: 0
            });
        }
    }]
});

Summary

smooth-scroll is a lightweight library focused on providing smooth scrolling functionality, making it easy to implement with minimal configuration. However, it lacks the advanced page transition and animation features offered by Barba. Barba, on the other hand, provides a more comprehensive solution for creating fluid and dynamic website transitions, but may have a steeper learning curve and require additional setup. The choice between the two depends on the specific needs of your project and the level of complexity you're aiming for in your website's interactions.

3,068

The most versatile JavaScript typewriter effect library on the planet.

Pros of TypeIt

  • Focused specifically on creating typewriter effects, offering more specialized features for this purpose
  • Lightweight and easy to integrate into existing projects
  • Provides a simple API for creating complex typing animations

Cons of TypeIt

  • Limited to typewriter animations, less versatile for general page transitions
  • Requires JavaScript to function, potentially impacting SEO and accessibility
  • May not be suitable for large-scale applications with complex navigation needs

Code Comparison

TypeIt:

new TypeIt("#element", {
  strings: "This is a typewriter effect!",
  speed: 50,
  waitUntilVisible: true
}).go();

Barba:

barba.init({
  transitions: [{
    leave(data) {
      return gsap.to(data.current.container, {opacity: 0});
    },
    enter(data) {
      return gsap.from(data.next.container, {opacity: 0});
    }
  }]
});

TypeIt excels at creating typewriter effects with a simple API, while Barba offers a more comprehensive solution for page transitions and dynamic content loading. TypeIt is ideal for projects requiring specific typing animations, whereas Barba is better suited for larger applications needing smooth page transitions and enhanced user experience across multiple pages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

barba.js Ҁ“ Stability CircleCI Coverage Status Commitizen friendly Conventional Commits lerna License All Contributors Slack workspace

Create badass, fluid and smooth transitions between your websiteҀ™s pages.

barbajs

Intro

Barba.js Ҁ” aka Barba Ҁ” is a small (7kb minified and compressed) and easy-to-use library that helps you create fluid and smooth transitions between your website's pages. It makes your website run like a SPA (Single Page Application) and help reduce the delay between your pages, minimize browser HTTP requests and enhance your user's web experience.

Features

Barba is user friendly, smart, extensible and futureproof. The library provides a bunch of useful features that will make your website shine like any other website, ever!

Documentation

Here you will find the documentation describing how to use the library.

  1. Website - official Barba website
  2. User guide - how to install and use the plugin
  3. Lessons, courses and videos - for in-depth learning
  4. Showcase - selected works made with Barba
  5. Developer API - by developers, for developers

[!NOTE] This guide assumes intermediate knowledge of HTML, CSS, and JavaScript. It is worth mentioning that all code examples use ES6+ syntax. If you are not comfortable with this syntax, we would encourage you to grasp the basics then come back.

In case of emergency, check the "legacy" code example.

Sponsor

If you like this library and want to give some recognition, it is now possible to become a Github sponsor and support this project by sponsoring BarbaJS maintainer on Github. Even if it's a small contribution, you participate in the effort of making open source projects maintained for anyone, and developers to be rewarded for their work/time.

Contribute

If you want to report a bug or request a new feature/improvement, please read the project contributors guidelines before.

Thanks for taking time to contribute to Barba :tada: :+1:

Contributors

Luigi De Rosa
Luigi De Rosa

Γ°ΒŸΒ€Β” Γ°ΒŸΒ’Β» Γ°ΒŸΒ“Β– Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ› Қ ï¸ Γ°ΒŸΒ‘Β€ Γ°ΒŸΒšΒ‡
Thierry Michel
Thierry Michel

Γ°ΒŸΒ€Β” Γ°ΒŸΒ’Β» Γ°ΒŸΒ“Β– Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ› Қ ï¸ Γ°ΒŸΒ‘Β€ Γ°ΒŸΒšΒ‡
Xavier Foucrier
Xavier Foucrier

Γ°ΒŸΒ€Β” Γ°ΒŸΒ’Β» Γ°ΒŸΒ“Β– Γ°ΒŸΒ’Β¬ Қ ï¸ Γ°ΒŸΒ‘Β€ Γ°ΒŸΒΒ› Γ°ΒŸΒšΒ‡
Marco Grimaldi
Marco Grimaldi

🎨
Petr TIchy
Petr TIchy

Γ°ΒŸΒ“Β Γ’ΒœΒ… Γ°ΒŸΒ“ΒΉ
Cody Marcoux
Cody Marcoux

Γ°ΒŸΒ’Β¬
Phil.
Phil.

Γ°ΒŸΒ’Β¬
Giorgio Finulli
Giorgio Finulli

Γ°ΒŸΒ’Β¬
Wouter
Wouter

Γ°ΒŸΒΒ› Γ°ΒŸΒ’Β¬
Mike Wagz
Mike Wagz

Γ°ΒŸΒ€Β” Γ°ΒŸΒ’Β¬ Қ ï¸
Red Stapler
Red Stapler

Γ’ΒœΒ… Γ°ΒŸΒ“ΒΉ
Jérémy Levron
Jérémy Levron

Γ°ΒŸΒ’Β¬
Nguyen Van Anh
Nguyen Van Anh

Γ°ΒŸΒ’Β»
Daniel Weber
Daniel Weber

Γ°ΒŸΒ’Β»
Jean-Marie Porchet
Jean-Marie Porchet

Γ°ΒŸΒ’Β»
James
James

Γ°ΒŸΒ’Β»
Nicholas
Nicholas

Γ°ΒŸΒ’Β»
Patrick Arminio
Patrick Arminio

Γ°ΒŸΒ’Β»
A (from Sicily)
A (from Sicily)

Γ°ΒŸΒ’Β»
Pavel Mazhuga
Pavel Mazhuga

Γ°ΒŸΒ’Β¬
Daniele De Matteo
Daniele De Matteo

Γ°ΒŸΒ’Β¬
aswinkumar863
aswinkumar863

Γ°ΒŸΒ’Β¬
BounceIncHQ
BounceIncHQ

Γ°ΒŸΒ’Β¬
gordonwes
gordonwes

Γ°ΒŸΒ’Β¬
Evan Fleet
Evan Fleet

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ›
Jârg
Jârg

Γ°ΒŸΒ’Β‘
ZAAK
ZAAK

Γ°ΒŸΒ’Β‘ Γ°ΒŸΒ’Β¬
Masahiro Tonomura
Masahiro Tonomura

Γ°ΒŸΒ’Β‘
CassiusHR
CassiusHR

Γ°ΒŸΒ’Β¬
Shane Murphy
Shane Murphy

Γ°ΒŸΒ’Β¬
Dylan Reeves
Dylan Reeves

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒ’Β‘
Quentin Neyraud
Quentin Neyraud

Γ°ΒŸΒ’Β¬
tortilaman
tortilaman

Γ°ΒŸΒ’Β¬
psntr
psntr

Γ°ΒŸΒ’Β¬
Kevin Clark
Kevin Clark

Γ°ΒŸΒ’Β¬
Tadeas Kosek
Tadeas Kosek

Γ°ΒŸΒ’Β¬
Gustavo de Andrade
Gustavo de Andrade

Γ°ΒŸΒ’Β¬
Clinton
Clinton

Γ°ΒŸΒ’Β¬
Dave Stockley
Dave Stockley

Γ°ΒŸΒ’Β¬
khaiknievel
khaiknievel

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ›
Francesco Michelini
Francesco Michelini

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒ’Β‘
Domantas Petrauskas
Domantas Petrauskas

Γ°ΒŸΒ’Β¬
Kyle Brumm
Kyle Brumm

Γ°ΒŸΒ’Β¬
Oliver Belmont
Oliver Belmont

Γ°ΒŸΒ’Β¬
Lu Nelson
Lu Nelson

Γ°ΒŸΒ’Β¬
Bram Cordie
Bram Cordie

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒ€Β”
Michael Schouman
Michael Schouman

Γ°ΒŸΒ’Β¬
Pascal Garber
Pascal Garber

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒ€Β”
Federico Brigante
Federico Brigante

Γ°ΒŸΒ’Β¬
Corey Lee
Corey Lee

Γ°ΒŸΒ’Β¬
Milan Simonovic
Milan Simonovic

Γ°ΒŸΒ’Β¬
Julien Vasseur
Julien Vasseur

Γ°ΒŸΒ’Β¬
Maciej Wrona
Maciej Wrona

Γ°ΒŸΒ’Β¬
Terion
Terion

Γ°ΒŸΒ€Β”
Matt Seccafien
Matt Seccafien

Γ°ΒŸΒ€Β”
Max Schulmeister
Max Schulmeister

Γ°ΒŸΒ€Β”
David
David

Γ°ΒŸΒ€Β”
Pierre-Henri Lavigne
Pierre-Henri Lavigne

Γ°ΒŸΒ€Β”
lsbyerley
lsbyerley

Γ°ΒŸΒ€Β”
Guillaume M.
Guillaume M.

Γ°ΒŸΒ€Β”
Oscar Otero
Oscar Otero

Γ°ΒŸΒ€Β”
Nico Prat
Nico Prat

Γ°ΒŸΒ€Β”
Marco Solazzi
Marco Solazzi

Γ°ΒŸΒΒ›
atoupet-toki
atoupet-toki

Γ°ΒŸΒΒ›
Josias
Josias

Γ°ΒŸΒΒ›
Oksana Romaniv
Oksana Romaniv

Γ°ΒŸΒΒ›
Olivier Guilleux
Olivier Guilleux

Γ°ΒŸΒΒ›
Liroo Pierre Γ‘Β΅ΒˆΓ‘Β΅Β‰Γ‘Β΅Β›
Liroo Pierre Γ‘Β΅ΒˆΓ‘Β΅Β‰Γ‘Β΅Β›

Γ°ΒŸΒ’Β»
Luis Martins
Luis Martins

Γ°ΒŸΒΒ›
Matthew
Matthew

Γ°ΒŸΒ€Β” Γ°ΒŸΒ’Β¬
Simon Goetz
Simon Goetz

Γ°ΒŸΒΒ›
Luís Carvalho
Luís Carvalho

Γ°ΒŸΒ’Β¬
Samuel Berisha
Samuel Berisha

Γ°ΒŸΒ’Β¬
Anderson Leite
Anderson Leite

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ›
Jay Collett
Jay Collett

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ›
Tim Gates
Tim Gates

Γ°ΒŸΒΒ›
Nicolas Cusan
Nicolas Cusan

Γ°ΒŸΒ’Β¬ Γ°ΒŸΒΒ› Γ°ΒŸΒ’Β»
Gerald Nako
Gerald Nako

Γ°ΒŸΒΒ› Γ°ΒŸΒ’Β»

License

The project is developed under the MIT license:

  • Permissions: This software and derivatives may be used for commercial purposes, you may distribute this software, this software may be modified and you may use and modify the software without distributing it.
  • Conditions: Include a copy of the license and copyright notice with the code.
  • Limitations: Software is provided without warranty and the software author/license owner cannot be held liable for damages.

Read the full license for more information about your rights.

NPM DownloadsLast 30 Days