Teleport

A lightweight layout library for responsive web pages which enables content folding (also referred to as interdigitation).

You may want to pursue a simpler, non-JS dependent layout technique using inline-block, floats, flexbox etc. However, Teleport allows for some sophisticated layouts which cannot be achieved (?) using existing CSS-only solutions and which are a requirement of some content-rich web pages such as the BBC Sport Homepage (which this library was developed for).

Install

Simply include teleport.js into your page (also available as an AMD module or CommonJS export).

Usage

<div id="container">
  <div data-teleport-region>
    <div id="a" data-teleport="default">A</div>
  </div>
  <div data-teleport-region>
    <!--teleport:ex-a-mod-a@big-->
  </div>
</div>
<script>
  var teleport = new Teleport({
    container: '#container',
    breakpoints: {
      big: '(min-width: 600px)'
    }
  });
</script>

Features

Browser Support

Should be supported in any modern(ish) version of Chrome, FF, Safari, IE9+ (for IE9 support you'll need to use a polyfill for matchMedia).

Run Tests

First install NPM packages:

npm install

Then start up a Selenium server e.g.

npm install selenium-standalone@latest -g
selenium-standalone install
selenium-standalone start

Then fire up a web server on port 8000 e.g.

python -m SimpleHTTPServer

Finally run the tests:

wdio wdio.conf.js

So, what now?

View source to see how this works, resize your browser to see Teleport in action or open in GitHub.

Examples

Scroll down to see some examples of Teleport in action (these also serve as fixtures for tests!)

Example A: Simple

Region 1

A: I teleport from region 1 to region 2 at 600px
B: I am static

Region 2

C: I am static

Example B: Complex

Region 1

A: I teleport from region 1 to region 3 at 400px
B: I am static

Region 2

C: I live in region 2 up to 400px and also at 1000px. I live in region 3 at 400px and region 4 at 700px

Region 3

D: I am static
E: I am static

Region 4

F: I teleport from region 4 at up to 400px, to 3 at up to 700px, to 2 at up to 1000px, to 1 over 1000px
G: I am static

Example C: Defaults

Region 1

Region 2

A: I default to region 2, teleporting to 1 @medium

Region 3

B: I default to region 1, teleporting to 3 @medium or @wide

Example D: Nested Teleport

Region 1

A: I move into nested teleport @big
B: I am static

Example E: Trigger State Change

Region 1

A: I teleport through each region when the "Next" button is pressed

Region 2

Region 3

Region 4