Convert Figma logo to code with AI

Dogstudio logohighway

Highway - A Modern Javascript Transitions Manager

1,425
92
1,425
4

Top Related Projects

4,605

Versatile and extensible page transition library for server-rendered websites 🎉

11,577

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

Turbolinks makes navigating your web application faster

6,701

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

11,577

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

Unobtrusive page transitions with jQuery.

Quick Overview

Highway is a modern and lightweight JavaScript library for creating smooth page transitions. It provides an easy-to-use API for managing route changes and animating content transitions, enhancing the user experience of single-page applications and static websites.

Pros

  • Lightweight and performant, with minimal dependencies
  • Flexible and customizable, allowing for complex transition animations
  • Easy integration with existing projects and frameworks
  • Well-documented with clear examples and API reference

Cons

  • Limited browser support for older versions (IE11 not supported)
  • May require additional setup for complex routing scenarios
  • Learning curve for advanced usage and custom transitions
  • Potential conflicts with other routing libraries if not configured properly

Code Examples

  1. Basic usage:
import Highway from '@dogstudio/highway';

const H = new Highway.Core();

This code initializes Highway and sets up the core functionality.

  1. Creating a custom transition:
import Highway from '@dogstudio/highway';

class FadeTransition extends Highway.Transition {
  in({ from, to, done }) {
    from.remove();
    gsap.fromTo(to, { opacity: 0 }, { opacity: 1, duration: 0.5, onComplete: done });
  }

  out({ from, done }) {
    gsap.to(from, { opacity: 0, duration: 0.5, onComplete: done });
  }
}

const H = new Highway.Core({
  transitions: {
    default: FadeTransition
  }
});

This example creates a custom fade transition using GSAP for animation.

  1. Handling route events:
import Highway from '@dogstudio/highway';

const H = new Highway.Core();

H.on('NAVIGATE_IN', ({ to, location }) => {
  console.log(`Navigating to: ${location.href}`);
});

H.on('NAVIGATE_END', ({ to, from, location }) => {
  console.log(`Navigation complete: ${location.href}`);
});

This code demonstrates how to listen for navigation events and perform actions accordingly.

Getting Started

  1. Install Highway:
npm install @dogstudio/highway
  1. Import and initialize Highway in your main JavaScript file:
import Highway from '@dogstudio/highway';

const H = new Highway.Core();
  1. Add the data-router-view attribute to your main content wrapper in your HTML:
<main data-router-view="main">
  <!-- Your page content here -->
</main>
  1. Create transitions and renderers as needed, and add them to your Highway instance:
import CustomTransition from './transitions/CustomTransition';
import CustomRenderer from './renderers/CustomRenderer';

const H = new Highway.Core({
  transitions: {
    default: CustomTransition
  },
  renderers: {
    main: CustomRenderer
  }
});

Competitor Comparisons

4,605

Versatile and extensible page transition library for server-rendered websites 🎉

Pros of swup

  • Smaller file size and lighter weight
  • More extensive documentation and examples
  • Wider browser compatibility, including older versions

Cons of swup

  • Less flexible animation options
  • Requires more setup for complex transitions
  • Limited built-in caching mechanisms

Code Comparison

swup:

const swup = new Swup();

swup.on('contentReplaced', () => {
  // Do something after content is replaced
});

Highway:

const H = new Highway.Core();

class Fade extends Highway.Transition {
  in({ from, to, done }) {
    // Animation logic here
    done();
  }
}

H.registerTransition(Fade);

Key Differences

  • swup focuses on simplicity and ease of use, while Highway offers more control over transitions
  • Highway provides a more object-oriented approach with separate transition classes
  • swup has a simpler API, making it easier for beginners to implement
  • Highway offers more advanced features for complex animations and page transitions

Both libraries aim to enhance the user experience by providing smooth page transitions in single-page applications. The choice between them depends on the specific requirements of your project and your preferred level of control over animations.

11,577

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

Pros of Barba

  • More mature and established project with a larger community and ecosystem
  • Offers a wider range of transitions and animations out of the box
  • Provides better documentation and examples for easier implementation

Cons of Barba

  • Slightly larger file size, which may impact page load times
  • More complex setup process for advanced features
  • Less flexible for highly customized transitions compared to Highway

Code Comparison

Highway:

const H = new Highway.Core();

H.on('NAVIGATE_IN', ({ to, location }) => {
  // Do something when the page is loaded
});

Barba:

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});
    }
  }]
});

Both libraries aim to create smooth page transitions in single-page applications, but they differ in their approach and feature set. Highway focuses on simplicity and flexibility, while Barba offers more built-in functionality and a larger ecosystem. The choice between the two depends on the specific needs of your project and your preferred level of customization.

Turbolinks makes navigating your web application faster

Pros of Turbolinks

  • Seamless integration with Ruby on Rails applications
  • Automatic handling of browser history and URL updates
  • Extensive documentation and large community support

Cons of Turbolinks

  • Limited customization options for transitions and animations
  • Potential conflicts with JavaScript-heavy applications
  • Steeper learning curve for developers unfamiliar with Ruby on Rails

Code Comparison

Turbolinks:

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

Highway:

import Highway from '@dogstudio/highway';

const H = new Highway.Core({
  transitions: {
    default: Fade
  }
});

Key Differences

  • Highway is a standalone JavaScript library, while Turbolinks is primarily designed for Ruby on Rails applications
  • Highway offers more flexibility in creating custom transitions and animations
  • Turbolinks focuses on speed and simplicity, while Highway emphasizes creative freedom in page transitions

Use Cases

  • Turbolinks: Ideal for Ruby on Rails applications seeking improved performance without major changes to the existing codebase
  • Highway: Best suited for projects requiring highly customized and visually appealing page transitions, especially in creative or portfolio websites

Both libraries aim to enhance the user experience by providing smoother navigation between pages, but they cater to different development environments and project requirements.

6,701

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

Pros of Turbo

  • Integrated with Ruby on Rails, offering seamless server-side rendering and progressive enhancement
  • Supports real-time updates through Turbo Streams, enabling dynamic content without full page reloads
  • Provides a complete solution for building modern web applications with less JavaScript

Cons of Turbo

  • Steeper learning curve for developers not familiar with Ruby on Rails ecosystem
  • Less flexibility for custom animations and transitions compared to Highway
  • May require more server-side logic and configuration

Code Comparison

Highway (basic navigation):

const H = new Highway.Core();

H.on('NAVIGATE_IN', ({ to, location }) => {
  console.log(`Navigating to: ${location.href}`);
});

Turbo (basic navigation):

import { Turbo } from "@hotwired/turbo-rails"

document.addEventListener("turbo:load", () => {
  console.log("Page loaded:", location.href);
});

Both libraries aim to enhance web navigation, but Highway focuses on smooth page transitions and animations, while Turbo provides a more comprehensive solution for building modern web applications with less client-side JavaScript. Highway offers more control over animations, while Turbo integrates tightly with Ruby on Rails and provides real-time update capabilities.

11,577

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

Pros of Barba

  • More mature and established project with a larger community and ecosystem
  • Offers a wider range of transitions and animations out of the box
  • Provides better documentation and examples for easier implementation

Cons of Barba

  • Slightly larger file size, which may impact page load times
  • More complex setup process for advanced features
  • Less flexible for highly customized transitions compared to Highway

Code Comparison

Highway:

const H = new Highway.Core();

H.on('NAVIGATE_IN', ({ to, location }) => {
  // Do something when the page is loaded
});

Barba:

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});
    }
  }]
});

Both libraries aim to create smooth page transitions in single-page applications, but they differ in their approach and feature set. Highway focuses on simplicity and flexibility, while Barba offers more built-in functionality and a larger ecosystem. The choice between the two depends on the specific needs of your project and your preferred level of customization.

Unobtrusive page transitions with jQuery.

Pros of smoothState.js

  • Simpler implementation for basic page transitions
  • Lightweight and focused on smooth page transitions
  • Easier to integrate into existing projects without major restructuring

Cons of smoothState.js

  • Less feature-rich compared to Highway
  • Limited customization options for complex transitions
  • Not actively maintained (last update in 2017)

Code Comparison

smoothState.js:

$('#main').smoothState({
  onStart: {
    duration: 250,
    render: function ($container) {
      $container.addClass('is-exiting');
    }
  }
});

Highway:

class Fade extends Highway.Transition {
  in({ from, to, done }) {
    from.remove();
    gsap.fromTo(to, { opacity: 0 }, { opacity: 1, onComplete: done });
  }
  out({ from, done }) {
    gsap.to(from, { opacity: 0, onComplete: done });
  }
}

Summary

While smoothState.js offers a simpler approach to page transitions, Highway provides more advanced features and customization options. smoothState.js may be suitable for smaller projects or quick implementations, whereas Highway is better suited for complex, modern web applications requiring sophisticated transitions and animations. Highway also benefits from active maintenance and a more recent codebase.

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

Highway

npm npm GitHub issues bundlephobia NpmLicense


⚠️ ⚠️ ⚠️

This repository is no longer maintained.
The v2.2.1 release will be the last one and no more updates will be done on Highway from now on.

Thanks to all the contributors, maintainers and to the community that motivated us to make Highway one of the best transition manager so far. Highway and its Slack will remain available. As long as the community keeps enjoying the library in its current state, there is no reasons for us to archive the repository.

⚠️ ⚠️ ⚠️


Banner

Highway is a lightweight (2.5ko compressed & gzipped), robust, modern and flexible library that will let us create AJAX navigations with beautiful transitions on our websites. It's been a while we were trying to build this kind of library to fits our needs at Dogstudio and we now finally released it!

Banner

Table of Content

Browser Support

Highway is supported by all recent major versions of the following modern browsers.

  • Google Chrome
  • Firefox
  • Edge
  • Safari

With polyfills

Older browsers or versions can be supported by Highway by combining it with polyfills. Please follow this example to have more information. Once the polyfills are configured, Highway should be working on most of the browsers and versions. However, be aware that the oldest browsers or versions might still be unsupported. So, be reasonable before opening an issue...

  • Google Chrome
  • Firefox
  • Edge
  • Safari
  • Internet Explorer 11

Roadmap

  • More Unit Tests
  • More Examples
  • More Demos

Releases

2.2.x

  • :lock: Update dependencies for security purposes
  • :tada: Add new websites in the Hall of Fame
  • :tada: Add Polyfills example to documentation
  • :sparkles: Reduce bundle size significantly with microbundle
  • :art: Update browser support in documentation
  • :art: Update browser support in README.md
  • :bug: Fix Slack URL in documentation
  • :bug: Fix Slack URL in README.md
  • :bug: Fix #77

2.1.x

  • :lock: Update dependencies for security purposes
  • :tada: Add trigger information in transitions and events
  • :tada: Add contextual transitions
  • :tada: Add overlapping transitions
  • :sparkles: Add Prefetch example to documentation
  • :sparkles: Improve transitions and events parameters for destructuring
  • :sparkles: Improve documentation website
  • :sparkles: Improve Core.redirect(href, transition) method
  • :sparkles: Improve Core.attach(links) method
  • :sparkles: Improve Core.detach(links) method
  • :art: Invert from and to parameters of the NAVIGATE_END event
  • :bug: Fix issue #44

2.0.x

  • :tada: Add documentation website
  • :tada: Add Core.redirect(href) method
  • :tada: Add dynamic import for renderers
  • :art: Update informations sent with events
  • :art: Rename Core.bind() into Core.attach()
  • :art: Rename Core.unbind() into Core.dettach()
  • :art: Rename Renderer.root into Renderer.view
  • :art: Replace Renderer.page by Renderer.properties
  • :bug: Fix pushState location in the process
  • :bug: Fix CMD/CTRL + click behavior of browsers
  • :bug: Fix NAVIGATE_IN event that was fired too early
  • :bug: Fix the view swapping that causes so issues
  • :bug: Fix page caching with queries
  • :bug: Fix issue #9
  • :bug: Fix issue #12
  • :sparkles: Improve overall code
  • :fire: Remove NAVIGATE_ERROR event
  • :fire: Clean up README.md

1.3.x

  • :tada: Add ES5 version in dist/es5 folder
  • :tada: Add the Basic Anchor example
  • :tada: Add the Basic Polyfill example
  • :tada: Add unit tests
  • :fire: Remove modes that weren't convincing
  • :sparkles: Improve code and weight with ES2016+ features
  • :sparkles: Improve events
  • :sparkles: Improve transitions
  • :sparkles: Improve documentation
  • :art: Rename renderers init method to setup method
  • :bug: Quick fix for URLs with parameters
  • :bug: Fix events
  • :bug: Fix helpers
  • :bug: Skip link with javascript: in href

1.2.x

  • :tada: Add NAVIGATE_CALL, NAVIGATE_IN, NAVIGATE_OUT events
  • :tada: Add more variables available in Highway.Renderer
  • :sparkles: Improve renderers
  • :sparkles: Improve documentation

1.1.x

  • :tada: Add modes
  • :sparkles: Improve documentation

1.0.x

  • :tada: Add Highway.Transition

0.0.x

  • :rocket: First release

Contributors


Anthony Du Pont

💬 💻 📖
🤔 🚧 👀

ThaoD5

💬 💻 📖
🤔 🚧 👀

Josh Kirk

💻 📖 🤔
🚧

Mike Wagz

📖 🚇


Suyash Purwar

💻 🐛


Davide Lanfranchi

🖋


Fabio Quarantini

💻 🐛


Quentin Neyraud

💻 🐛


Harvey Zack

💻


Stijn de Jong

💻 🐛

License

See the LICENSE file for license rights and limitations (MIT).

NPM DownloadsLast 30 Days