From 0bd410e15d6e2df7b54afbbf9cbdcde42fef4f78 Mon Sep 17 00:00:00 2001 From: rezemble <689071+rezemble@users.noreply.github.com> Date: Wed, 15 Jul 2020 12:41:32 +0200 Subject: [PATCH 1/5] emit actual event --- src/sticky.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sticky.js b/src/sticky.js index 1e50d22..b909dd6 100644 --- a/src/sticky.js +++ b/src/sticky.js @@ -132,7 +132,6 @@ class Sticky { fireEvents() { if ( - typeof this.options.onStick === 'function' && (this.lastState.top !== this.state.isTopSticky || this.lastState.bottom !== this.state.isBottomSticky || this.lastState.sticked !== @@ -143,7 +142,8 @@ class Sticky { bottom: this.state.isBottomSticky, sticked: this.state.isBottomSticky || this.state.isTopSticky, }; - this.options.onStick(this.lastState); + if (typeof this.options.onStick === 'function') this.options.onStick(this.lastState); + this.vm.$emit(this.lastState) } } From 1467ef3f2024da9f7efc1c056bff2873724378ae Mon Sep 17 00:00:00 2001 From: rezemble <689071+rezemble@users.noreply.github.com> Date: Wed, 15 Jul 2020 12:42:21 +0200 Subject: [PATCH 2/5] actually name the event... --- src/sticky.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sticky.js b/src/sticky.js index b909dd6..ce82c98 100644 --- a/src/sticky.js +++ b/src/sticky.js @@ -143,7 +143,7 @@ class Sticky { sticked: this.state.isBottomSticky || this.state.isTopSticky, }; if (typeof this.options.onStick === 'function') this.options.onStick(this.lastState); - this.vm.$emit(this.lastState) + this.vm.$emit('stick', this.lastState) } } From 93d61a0fe543afe4094393af78fb7ace81373a88 Mon Sep 17 00:00:00 2001 From: rezemble <689071+rezemble@users.noreply.github.com> Date: Wed, 15 Jul 2020 12:54:04 +0200 Subject: [PATCH 3/5] Events work differently in directives --- src/sticky.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sticky.js b/src/sticky.js index ce82c98..d1b5894 100644 --- a/src/sticky.js +++ b/src/sticky.js @@ -23,9 +23,10 @@ const batchStyle = (el, style = {}, className = {}) => { }; class Sticky { - constructor(el, vm) { + constructor(el, vm, vnode) { this.el = el; this.vm = vm; + this.vnode = vnode; this.unsubscribers = []; this.isPending = false; this.state = { @@ -143,7 +144,7 @@ class Sticky { sticked: this.state.isBottomSticky || this.state.isTopSticky, }; if (typeof this.options.onStick === 'function') this.options.onStick(this.lastState); - this.vm.$emit('stick', this.lastState) + if (this.vnode.data && this.vnode.data.on && this.vnode.data.on.stick) this.vnode.data.on.stick(this.lastState) } } @@ -273,7 +274,7 @@ class Sticky { export default { inserted(el, bind, vnode) { if (typeof bind.value === 'undefined' || bind.value) { - el[namespace] = new Sticky(el, vnode.context); + el[namespace] = new Sticky(el, vnode.context, vnode); el[namespace].doBind(); } }, From 46560f3f7a0ca102afacd1e599203bec01ebb37f Mon Sep 17 00:00:00 2001 From: rezemble <689071+rezemble@users.noreply.github.com> Date: Wed, 15 Jul 2020 12:54:50 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ee24e85..1a7593c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ Use `v-sticky` directive to enable element postion sticky, and use `sticky-*` at * `sticky-z-index` _(number)_ - to set the z-index of element to stick * `on-stick` _(function)_ - callback when sticky and release, receiveing 1 argument with object indicating the state, like: +# Events +* `@stick` - Same as `on-stick`-callback, but as an event + ```javascript // The element is sticked on top { From 1fe87c33711e51390ee663a2703644ed5b47d8ec Mon Sep 17 00:00:00 2001 From: rezemble <689071+rezemble@users.noreply.github.com> Date: Wed, 15 Jul 2020 12:55:29 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1a7593c..a99c358 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,8 @@ Use `v-sticky` directive to enable element postion sticky, and use `sticky-*` at * `sticky-z-index` _(number)_ - to set the z-index of element to stick * `on-stick` _(function)_ - callback when sticky and release, receiveing 1 argument with object indicating the state, like: -# Events -* `@stick` - Same as `on-stick`-callback, but as an event - ```javascript -// The element is sticked on top +// The element is stuck on top { bottom: false, top: true, @@ -55,7 +52,10 @@ Use `v-sticky` directive to enable element postion sticky, and use `sticky-*` at } ``` -An expression that evaluates to false set on `v-sticky` can be used to disable stickiness condtionally. +# Events +* `@stick` - Same as `on-stick`-callback, but as an event + +An expression that evaluates to false set on `v-sticky` can be used to disable stickiness conditionally. ```HTML