mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add twitter button
This commit is contained in:
parent
4a3c96b95d
commit
3f5f0eb764
2 changed files with 101 additions and 1 deletions
71
components/twitter-follow.vue
Normal file
71
components/twitter-follow.vue
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<template>
|
||||
|
||||
<div
|
||||
:class="[
|
||||
'h-8 transition-opacity duration-500 ease-in-out',
|
||||
visible ? 'opacity-100' : 'opacity-0'
|
||||
]"
|
||||
>
|
||||
|
||||
<a
|
||||
ref="follow"
|
||||
href="https://twitter.com/doesitarm?ref_src=twsrc%5Etfw"
|
||||
class="twitter-follow-button"
|
||||
data-show-count="false"
|
||||
>Follow @doesitarm</a>
|
||||
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import { observeElementInViewport } from 'observe-element-in-viewport'
|
||||
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
// https://platform.twitter.com/widgets.js
|
||||
|
||||
// the returned function, when called, stops tracking the target element in the
|
||||
// given viewport
|
||||
const unobserve = observeElementInViewport(this.$refs.follow, async (_, unobserve, expandZoneElem) => {
|
||||
// On element enter viewport
|
||||
// console.log('Entered', logoRef)
|
||||
|
||||
this.loadTwitterScript()
|
||||
|
||||
// Turn off this observer
|
||||
unobserve()
|
||||
}, () => {
|
||||
// On element exit viewport
|
||||
// console.log('Exited', logoRef)
|
||||
}, {
|
||||
threshold: [ 0 ]
|
||||
})
|
||||
|
||||
},
|
||||
methods: {
|
||||
loadTwitterScript () {
|
||||
const twitterScript = document.createElement('script')
|
||||
|
||||
twitterScript.setAttribute('charset','utf-8')
|
||||
twitterScript.setAttribute('async','true')
|
||||
twitterScript.setAttribute('src','https://platform.twitter.com/widgets.js')
|
||||
|
||||
document.head.appendChild(twitterScript)
|
||||
|
||||
|
||||
// Reveal after 200ms
|
||||
setInterval(() => {
|
||||
this.visible = true
|
||||
}, 750)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue