项目作者: bennyxguo

项目描述 :
Vue directive that supports top and bottom sticky base on pure js and vue.
高级语言: JavaScript
项目地址: git://github.com/bennyxguo/vuejs-sticky-directive.git
创建时间: 2018-07-21T03:39:58Z
项目社区:https://github.com/bennyxguo/vuejs-sticky-directive

开源协议:MIT License

下载


vuejs-sticky-directive

Support top and bottom sticky base on pure js and vue.


Build Status
Github starts
License
License

📑中文文档

Install

  1. npm install vue-sticky-directive --save

ES2015

  1. // register globally
  2. import Sticky from 'vuejs-sticky-directive'
  3. Vue.use(Sticky)
  4. // or for a single instance
  5. import Sticky from 'vuejs-sticky-directive'
  6. new Vue({
  7. directives: {Sticky}
  8. })

Usage

  • Use v-sticky directive to enable element postion sticky
  • Use sticky-* attributes to define its options
  • Sticky element will find its nearest element with sticky-container attribute or its parent node if faild as the releative element.

basic example

  1. <div sticky-container>
  2. <div v-sticky sticky-offset="offset" sticky-side="top">
  3. ...
  4. </div>
  5. </div>

Options

  • sticky-offset
    • top(number) - set the top breakpoint (default: 0)
    • bottom(number) - set the bottom breakpoint (default: 0)
  • sticky-side(string) decide which side should be sticky, you can set topbottom or both (default: top)
  1. <div sticky-container>
  2. <div v-sticky sticky-offset="offset" sticky-side="both">
  3. ...
  4. </div>
  5. </div>
  1. export defaults {
  2. data () {
  3. offset: {
  4. top: 0, // set the top breakpoint
  5. bottom: 44 // set the bottom breakpoint
  6. }
  7. }
  8. }

On/off switch

An expression that evaluates to false set on v-sticky can be used to disable stickiness condtionally.

  1. <div sticky-container>
  2. <div v-sticky="shouldStick">
  3. ...
  4. </div>
  5. </div>
  1. export defaults {
  2. data () {
  3. shouldStick: false
  4. }
  5. }

License

MIT

Reference/Source

Base on the package mehwww/vue-sticky-directive, this package fixed the bugs exist in the original package and also provide the continuous support.

Vue-stick-directive