• Stars
    star
    8,489
  • Rank 4,318 (Top 0.09 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated 8 months ago

Reviews

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

Repository Details

A positioning engine to make overlays, tooltips and dropdowns better

Tether

npm version Download count all time npm npm bundle size Build Status Maintainability Test Coverage

🐙 Project status 🐙

We at Ship Shape have recently taken over Tether's maintenance and hope to modernize and revitalize it. Stay tuned for updates!

Install

npm

npm install tether

For the latest beta:

npm install tether@next

download

Or download from the releases.

Introduction

Tether is a small, focused JavaScript library for defining and managing the position of user interface (UI) elements in relation to one another on a web page. It is a tool for web developers building features that require certain UI elements to be precisely positioned based on the location of another UI element.

There are often situations in UI development where elements need to be attached to other elements, but placing them right next to each other in the DOM tree can be problematic based on the context. For example, what happens if the element we’re attaching other elements to is fixed to the center of the screen? Or what if the element is inside a scrollable container? How can we prevent the attached element from being clipped as it disappears from view while a user is scrolling? Tether can solve all of these problems and more.

Some common UI elements that have been built with Tether are tooltips, select menus, and dropdown menus. Tether is flexible and can be used to solve all kinds of interesting problems; it ensures UI elements stay where they need to be, based on the various user interactions (click, scroll, etc) and layout contexts (fixed positioning, inside scrollable containers, etc).

Please have a look at the documentation for a more detailed explanation of why you might need Tether for your next project.

What to Use Tether for and When to Use It

Tether is a small, focused JavaScript library. For those who might be new to JavaScript, a library is simply a JavaScript file (or files) that contain useful JavaScript code to help achieve tasks easier and faster. Since Tether is a JavaScript user interface (UI) library, it contains code to help you to manage the way your website or web app appears.

Tether’s goal to is to help you position your elements side-by-side when needed.

Let’s say you’ve started working on your dream project—a fancy web app that’s sure to become the next big thing! An important feature of your new app is to allow users to comment on shared photos. However, due to limited vertical space and the overall layout of your new app, you’d like to display the comments next to the image, similar to how Instagram does it.

Your HTML code might look something like this:

<div class="container">
  <img src="awesome-picture.jpg" alt="Awesome Picture" class="picture">
  <div class="comments">
    ...
  </div>
</div>

Now, you could achieve this with some CSS using its position property, but going this route can be problematic since many of position’s values take elements out of the natural DOM flow. For example, if you have an element at the bottom of your HTML document, using position: absolute or position: fixed might could move it all the way to the top of your website in the browser.

Not only that, but you also have to make manual adjustments to ensure other elements aren’t negatively affected by the positioned elements. Not to mention, you probably want your comment box to be responsive, and look good across different device sizes. Coding a solution for this manually is a challenge all on its own.

Enter Tether!

After installing Tether and including it in your project, you can begin using it!

  1. In your JavaScript file, create a new instance (or constructor function) of the Tether object:

    new Tether({});
  2. Within the curly braces ({}) you can configure the library’s options. Tether’s extensive list of options can be found in the Tether documentation.

    new Tether({
      element: '.comments',
      target: '.picture',
      attachment: 'top right',
      targetAttachment: 'top left'
    });

Now you have a perfectly placed comment section to go with your awesome picture! It’ll even stay attached to the element when a user resizes their browser window.

There are tons of other useful features of Tether as well, instead of “comment boxes” you could also build:

  • Tooltips for useful hints and tricks,
  • Dropdown menus,
  • Autocomplete popups for forms,
  • and more!

Usage

You only need to include tether.min.js in your page:

<script src="path/to/dist/js/tether.min.js"></script>

Or use a CDN:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/tether.min.js"></script>

The css files are not required to get tether running.

For more details jump straight in to the detailed Usage page.

Tether Docs

Demo & API Documentation

Contributing

We encourage contributions of all kinds. If you would like to contribute in some way, please review our guidelines for contributing.

License

Copyright © 2019-2022 Ship Shape Consulting LLC - MIT License Copyright © 2014-2018 HubSpot - MIT License

More Repositories

1

shepherd

Guide your users through a tour of your app
JavaScript
11,579
star
2

react-shepherd

A React wrapper for the site tour library Shepherd
CSS
549
star
3

vue-shepherd

A Vue wrapper for the site tour library Shepherd
Vue
260
star
4

angular-shepherd

An Angular wrapper for the site tour library Shepherd
TypeScript
196
star
5

ember-cli-release

Ember CLI addon for versioned release management
JavaScript
90
star
6

swach

A robust color management tool for the modern age
TypeScript
52
star
7

ember-prism

Easy ember components for syntax highlighting a-la PrismJS
TypeScript
34
star
8

ember-cli-capacitor

Add Capacitor to your Ember app.
JavaScript
29
star
9

ember-x-editable

X-editable like library for Ember
JavaScript
22
star
10

ember-3d-nav

A 3d rotating top navigation bar for Ember apps
JavaScript
21
star
11

website-ember

The code for shipshape.io
JavaScript
20
star
12

website-nuxt

Nuxt port of shipshape.io
Vue
16
star
13

ember-cli-netlify

Ember addon to configure Netlify headers and redirects
JavaScript
14
star
14

ember-drop

An Ember addon that wraps Drop.js
JavaScript
11
star
15

website-astro

The code for the current Ship Shape website
Astro
6
star
16

prember-sitemap-generator

A sitemap generator for prember apps
JavaScript
6
star
17

ember-service-worker-prember

An Ember Service Worker plugin that caches the index.html files for each prember route
JavaScript
6
star
18

ember-3d-folding-panel

An Ember addon for 3d folding panels
JavaScript
5
star
19

starpod

Starpod: Create an amazing podcast website in 5 minutes
TypeScript
5
star
20

ember-headroom

Ember addon to include headroom.js as an ES2015 module in your app
JavaScript
4
star
21

ember-performance-workshop

The code for the EmberConf 2018 Performance Workshop
HTML
4
star
22

ember-newton-cradle-loader

Ember addon for showing a newton cradle loading animation
JavaScript
4
star
23

ember-async-await-for-each

async/await aware forEach for Ember
JavaScript
4
star
24

prember-rss-feed

Ship RSS feeds for your Prember site
JavaScript
3
star
25

ember-assign-polyfill

A polyfill for Ember.assign in <= 2.4
JavaScript
2
star
26

ember-journal

A blogging engine for Ember apps
JavaScript
2
star
27

ember-isometric-grids

JavaScript
2
star
28

bootcamp-loader

TypeScript
1
star
29

1787-astro

Astro
1
star
30

ember-debonair

Get your Ember code in ship shape
JavaScript
1
star
31

ember-showdown-highlight

JavaScript
1
star
32

glimmer-context-menu

TypeScript
1
star
33

www-website

whiskeywebandwhatnot.fm
JavaScript
1
star