Last active
February 10, 2021 13:53
-
-
Save fadamakis/939b2cf1aedd6713d1798d0389b78cb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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