当前位置: 首页 > 软件库 > 程序开发 > >

ember-sticky-element

授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 苏鸿才
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

ember-sticky-element

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, andnot widely supported natively. While there are polyfills available, they lacksome 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 efficientviewport 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 pointit will get sticky. This effectively makes it position: fixed. (Unfortunately for now this will require you to allowinline 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 whenscrolling the page all the way down. To make it also stick to the bottom of its parent (so it does not leave its parent'sboundaries), 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 thebottom 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.

 相关资料
  • 描述 (Description) Sticky插件用于在网站中创建恒定的内容或图像。 下表描述了不同类型的粘滞插件以及描述。 Sr.No. 类型和描述 1 Basics 要创建粘性类型容器,请在元素中包含类.sticky和[data-sticky] 。 2 Advanced data-top-anchor="idOfSomething"用于设置图像或内容,这是特定高度的粘性。 3 JavaScri

  • Sticky是一个简单的页面消息提醒jQuery插件。可以设置让消息在页面的四个角落出现,也可以设置在页面中央出现。可以手动关闭消息,也可以设置成自动关闭。 在线演示

  • Sticky 插件可在页面始终显示某个元素,并不会因为页面滚动而消失,也不会被其他元素覆盖。

  • Sticky Notes 是一个用来创建基于网页的即时贴的jQuery插件,即时贴的参数包括:size, color, position, draggbalility, resizability, opacity, onclose event, ondrag event, fade delays 等等。 依赖于: ui.mouse.js, ui.draggable.js, ui.resizable.js

  • 1.10.0 新增 吸附组件,当滚动位置到达目标元素位置后,目标元素就会自动吸附。 示例 综合使用 - Scroll <cube-sticky :pos="scrollY"> <cube-scroll :scroll-events="scrollEvents" @scroll="scrollHandler"> <ul> <li>title</li>

  • Sticky 吸顶 平台差异说明 App H5 微信小程序 支付宝小程序 百度小程序 头条小程序 QQ小程序 √ √ √ √ √ √ √ 基本使用 通过slot,将需要吸顶的内容放在Sticky组件中即可,slot中只能有一个根元素 注意! 由于页面依赖相关的原因的,部分页面会出现Cannot read property 'bottom' of null的报错,可以参考 issue #239 进行