All Projects → kaliber5 → Ember Sticky Element

kaliber5 / Ember Sticky Element

Licence: mit
An ember component that mimics the functionality of `position: sticky`

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ember Sticky Element

Docfy
Build fully personalized documentation sites; write content and demos in Markdown.
Stars: ✭ 48 (-5.88%)
Mutual labels:  ember, ember-addon
Ember Accessibility
An EmberJS addon to help identify accessibility violations during development
Stars: ✭ 29 (-43.14%)
Mutual labels:  ember, ember-addon
Ember Metrics
Send data to multiple analytics integrations without re-implementing new API
Stars: ✭ 356 (+598.04%)
Mutual labels:  ember, ember-addon
Ember I18n Changeset Validations
ember-i18n support for ember-changeset-validations messages
Stars: ✭ 11 (-78.43%)
Mutual labels:  ember, ember-addon
Ember Bootstrap
Ember-cli addon for using Bootstrap as native Ember components.
Stars: ✭ 475 (+831.37%)
Mutual labels:  ember, ember-addon
Ember Light Table
Lightweight, contextual component based table for Ember 2.3+
Stars: ✭ 310 (+507.84%)
Mutual labels:  ember, ember-addon
Ember Cli Flash
Simple, highly configurable flash messages for ember-cli
Stars: ✭ 358 (+601.96%)
Mutual labels:  ember, ember-addon
ember-render-helpers
Complimentary render template helpers to the render modifiers
Stars: ✭ 19 (-62.75%)
Mutual labels:  ember, ember-addon
Ember Cp Validations
Ember computed property based validations
Stars: ✭ 442 (+766.67%)
Mutual labels:  ember, ember-addon
Ember Intl
Localization library for any Ember Application or Addon
Stars: ✭ 412 (+707.84%)
Mutual labels:  ember, ember-addon
Ember Api Feature Flags
API based, read-only feature flags for Ember
Stars: ✭ 11 (-78.43%)
Mutual labels:  ember, ember-addon
Ember Polymer
Use Polymer in your ambitious Ember application! 💎
Stars: ✭ 20 (-60.78%)
Mutual labels:  ember, ember-addon
Ember Burger Menu
An off-canvas sidebar component with a collection of animations and styles using CSS transitions
Stars: ✭ 280 (+449.02%)
Mutual labels:  ember, ember-addon
Ember Websockets
Ember.js websockets and socket.io addon
Stars: ✭ 336 (+558.82%)
Mutual labels:  ember, ember-addon
Ember Apollo Client
🚀 An ember-cli addon for Apollo Client and GraphQL
Stars: ✭ 257 (+403.92%)
Mutual labels:  ember, ember-addon
Ember Simple Auth Token
Ember Simple Auth extension that is compatible with token-based authentication like JWT.
Stars: ✭ 356 (+598.04%)
Mutual labels:  ember, ember-addon
ember-gridstack
Ember components to build drag-and-drop multi-column grids powered by gridstack.js
Stars: ✭ 31 (-39.22%)
Mutual labels:  ember, ember-addon
ember-local-storage-decorator
Decorator for Ember.js to read and persist data in localStorage
Stars: ✭ 13 (-74.51%)
Mutual labels:  ember, ember-addon
Ember Decorators
Useful decorators for Ember applications.
Stars: ✭ 360 (+605.88%)
Mutual labels:  ember, ember-addon
Ember React Components
Render React components in Ember
Stars: ✭ 43 (-15.69%)
Mutual labels:  ember, ember-addon

ember-sticky-element

Build Status Ember Observer Score npm version Greenkeeper badge

This Ember addon gives you the ability to make parts of your UI stick to the viewport when scrolling. Its semantics follow roughly the proposed position: sticky specs.

See the Demo App for some examples!

Why should I use this

The mentioned CSS extension of position: sticky is still in a draft stage, and not widely supported natively. While there are polyfills available, they lack some features:

  • you cannot change the styling of your sticky element based on its state of being sticky or not
  • you cannot dynamically change the contents of the sticky element based on that state either

While there a probably a few jQuery plugins around for the same purpose, they might not always play well with Ember.

So this addon adds a sticky-element component, that mimics the basic position: sticky behaviour. Currently it only supports scrolling in the vertical direction, not horizontal stickiness yet.

It leverages ember-in-viewport under the hood for its efficient viewport detection techniques.

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

ember install ember-sticky-element

Usage

Just wrap your content into the sticky-element:

{{#sticky-element}}
  <h2>Sticky Element</h2>
{{/sticky-element}}

This will make it flow with the other content when scrolling until it reaches the top of the viewport, at which point it will get sticky. This effectively makes it position: fixed. (Unfortunately for now this will require you to allow inline styles if you use CSP!)

Customization options

Offsets

The behaviour of the component and its styling can be customized with the following options. Also see the Demo App for some examples.

Top offset

Add the top property to specify an offset in pixels from the top of the viewport:

{{#sticky-element top=50}}
  <h2>Sticky Element</h2>
{{/sticky-element}}
Bottom offset

By default the sticky element will not care about its parent enclosing element and just remain sticky to the top when scrolling the page all the way down. To make it also stick to the bottom of its parent (so it does not leave its parent's boundaries), just add the bottom property, with a value of 0 or some other offset:

{{#sticky-element top=50 bottom=0}}
  <h2>Sticky Element</h2>
{{/sticky-element}}

Make sure that the parent element has some positioning applied, so at least position: relative, as sticking to the bottom is done by applying position: absolute to the sticky element!

Disabling

You can set the enabled property to false to disable the sticky behavior:

{{#sticky-element enabled=someBooleanProperty}}
  <h2>Sticky Element</h2>
{{/sticky-element}}

Styling

CSS

The sticky element has a containerClassName property you can use for styling (by default .sticky-element). Furthermore additionals classes can be set: when being sticky:

  • containerStickyClassName (by default .sticky-element--sticky): when sticked either to the top or the bottom.
  • containerStickyTopClassName (by default .sticky-element--sticky-top): when sticked to the top.
  • containerStickyBottomClassName (by default .sticky-element--sticky-bottom): when sticked to the bottom.
Content

The component yields a hash, that contains the following boolean properties based on its state:

  • isSticky
  • isStickyTop
  • isStickyBottom

You can use these to change the content of the sticky element based on its state:

{{#sticky-element as |state|}}
  <h2>Sticky Element</h2>
  <p>{{#if state.isSticky}}Yeah, I am sticky!{{else}}I am just a normal element.{{/if}}</p>
{{/sticky-element}}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

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].