Skip to content

Instantly share code, notes, and snippets.

@fadamakis
Last active February 10, 2021 13:53
Show Gist options
  • Save fadamakis/939b2cf1aedd6713d1798d0389b78cb3 to your computer and use it in GitHub Desktop.
Save fadamakis/939b2cf1aedd6713d1798d0389b78cb3 to your computer and use it in GitHub Desktop.
<div id="dynamicexample">
<h3>Scroll down inside this section ↓</h3>
<p v-pin:[direction]="200">I am pinned onto the page at 200px to the left.</p>
</div>
Vue.directive('pin', {
bind: function (el, binding, vnode) {
el.style.position = 'fixed'
var s = (binding.arg == 'left' ? 'left' : 'top')
el.style[s] = binding.value + 'px'
}
})
new Vue({
el: '#dynamicexample',
data: function () {
return {
direction: 'left'
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment