All Projects → Rich-Harris → Ramjet

Rich-Harris / Ramjet

Licence: mit
Morph DOM elements from one state to another with smooth animations and transitions

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects
shell
77523 projects

Projects that are alternatives of or similar to Ramjet

Lax.js
Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.
Stars: ✭ 8,274 (+51.68%)
Mutual labels:  effects, transitions
React Navigation Magic Move
Bindings for using react-navigation with react-native-magic-move 🐰🎩✨
Stars: ✭ 132 (-97.58%)
Mutual labels:  effects, transitions
UnityGUI
UGUI Panel Systems for navigation, animation and more
Stars: ✭ 80 (-98.53%)
Mutual labels:  effects, transitions
Motus
Animation library that mimics CSS keyframes when scrolling.
Stars: ✭ 502 (-90.8%)
Mutual labels:  dom
Testing Playground
🐸 Simple and complete DOM testing playground that encourage good testing practices.
Stars: ✭ 511 (-90.63%)
Mutual labels:  dom
Html2canvas
Screenshots with JavaScript
Stars: ✭ 25,113 (+360.37%)
Mutual labels:  dom
Nanomorph
🚅 - Hyper fast diffing algorithm for real DOM nodes
Stars: ✭ 621 (-88.62%)
Mutual labels:  dom
Fused Effects
A fast, flexible, fused effect system for Haskell
Stars: ✭ 501 (-90.82%)
Mutual labels:  effects
Cash
An absurdly small jQuery alternative for modern browsers.
Stars: ✭ 5,714 (+4.75%)
Mutual labels:  dom
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (-90.14%)
Mutual labels:  effects
React Svg
🎨 A React component that injects SVG into the DOM.
Stars: ✭ 536 (-90.17%)
Mutual labels:  dom
React Motion Layout
🦸 Beautiful immersive React hero animations.
Stars: ✭ 509 (-90.67%)
Mutual labels:  transitions
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+351.26%)
Mutual labels:  dom
Reply
The 'Reply' Material Design case study built with Flutter.
Stars: ✭ 506 (-90.72%)
Mutual labels:  transitions
Displayjs
A simple JavaScript framework for building ambitious UIs 😊
Stars: ✭ 590 (-89.18%)
Mutual labels:  dom
Awesome
🚀A curated list of awesome resources related to Alpine.
Stars: ✭ 502 (-90.8%)
Mutual labels:  dom
React Log
React for the Console
Stars: ✭ 553 (-89.86%)
Mutual labels:  dom
Web Series
📚 现代 Web 开发语法基础与工程实践,涵盖 Web 开发基础、前端工程化、应用架构、性能与体验优化、混合开发、React 实践、Vue 实践、WebAssembly 等多方面。
Stars: ✭ 666 (-87.79%)
Mutual labels:  dom
Scrollbear
A modern tool that maintains scroll position when images loaded
Stars: ✭ 523 (-90.41%)
Mutual labels:  dom
Redux Saga
An alternative side effect model for Redux apps
Stars: ✭ 21,975 (+302.84%)
Mutual labels:  effects

ramjet

ramjet

Installation

npm install ramjet, or download ramjet.js.

Quick start

<div id='a' style='background-color: red; font-size: 4em; padding: 1em;'>a</div>
<div id='b' style='background-color: blue; font-size: 4em; padding: 1em;'>b</div>

<script src='ramjet.js'></script>
<script>
  var element1 = document.getElementById('a'),
      element2 = document.getElementById('b');

  // to repeat, run this from the console!
  ramjet.transform( element1, element2 );
</script>

Okay, so... what does this do?

Ramjet makes it look like your DOM elements are capable of transforming into one another. It does this by cloning the elements (and all their children), transforming the second element (the one we're transforming to) so that it completely overlaps with the first, then animating the two elements together until the first element (the one we're transitioning from) has exactly the same position and dimensions as the second element originally did.

It's basically the same technique used in iOS 8 to make it appear as though each app lives inside its icon.

ios8-effect

In modern browsers, it uses CSS animations, so everything happens off the main thread. The result is buttery-smooth performance, even on mobile devices.

API

ramjet.transform( a, b[, options] )

  • a is the DOM node we're transitioning from
  • b is the DOM node we're transitioning to
  • options can include the following properties:
    • done - a function that gets called once the transition completes
    • duration - the length of the transition, in milliseconds (default 400)
    • easing - a function used to control the animation. Should take a number between 0 and 1, and return something similar (though it can return a number outside those bounds, if you're doing e.g. an elastic easing function). I highly recommend eases by Matt DesLauriers, which is a handy collection of these functions
    • easingScale - if defined it will use a different easing function for scaling. It can be used to create cartoonish effects.
    • useTimer - by default, ramjet will use CSS animations. Sometimes (when transitioning to or from SVG elements, or in very old browsers) it will fall back to timer-based animations (i.e. with requestAnimationFrame or setTimeout). If you want to always use timers, make this option true - but I don't recommend it (it's much more juddery on mobile)
    • overrideClone (advanced) - look at the section Advanced options
    • appendToBody (advanced) - look at the section Advanced options

ramjet.hide( ...nodes )

Convenience function that sets the opacity of each node to 0 (temporarily disabling any transition that might otherwise interfere).

ramjet.show( ...nodes )

Opposite of ramjet.hide.

ramjet.linear, ramjet.easeIn, ramjet.easeOut, ramjet.easeInOut

A handful of easing functions, included for convenience.

Browser support

Successfully tested in IE9+, Chrome (desktop and Android), Firefox, Safari 6+ and mobile Safari - please raise an issue if your experience differs!

Developing and testing

Once you've cloned this repo and installed all the development dependencies (npm install), you can start a development server by running npm start and navigating to localhost:4567. Any changes to the source code (in the src directory) will be immediately reflected, courtesy of gobble.

To build, do npm run build.

Reliable automated tests of a library like ramjet are all but impossible. Instead npm test will start the development server and navigate you to localhost:4567/test.html, where you can visually check that the library behaves as expected.

Advanced options

The option overrideClone (function) overrides the function used to clone nodes (the default implementation uses a simple node.cloneNode()). It takes as a parameters the current node and the depth of this node compared to the original element (it is called recursively on the node subtree). It can be useful for removing annoying attributes or children from the cloned node. For example if a node contains a video element with autoplay, this can be excluded because it may be heavy to animate and you can heard the audio of it. Examples:

// cloning only the root node
ramjet.transform( element1, element2, {
  overrideClone: function (node, depth){
    if (depth == 0){
      return node.cloneNode(); // copy only the root node
    }
  }
});

// cloning everything but the id attribute
ramjet.transform( element1, element2, {
  overrideClone: function (node, depth){
    var clone = node.cloneNode();
    clone.removeAttr('id');
  }
});

// not cloning the video element
ramjet.transform( element1, element2, {
  overrideClone: function (node, depth){
    if (node.nodeType === 1 && node.tagName === "VIDEO"){
      return;
    }
    return node.cloneNode();
  }
});

By default the cloned nodes are appended to the parent to the original node. Inheriting the positioning and css inherited rules, they can behave in an unexpected way. For this reason you can use the flag appendToBody to append these nodes to the body instead. I invite everyone to set this to true and open an issue if it doesn't work, it may become the default in one of the next releases.

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].