Created
September 19, 2018 19:58
-
-
Save admench/a8f5b764a5dc85b104c4f1ad988a6ca4 to your computer and use it in GitHub Desktop.
Instantiate glide.js in Vue
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
<script> | |
const linkifyHtml = require("linkifyjs/html"); | |
import Glide from "@glidejs/glide"; | |
export default { | |
props: { | |
tweets: {} | |
}, | |
data() { | |
return { | |
glide: null | |
}; | |
}, | |
mounted() { | |
// this.slider = lory(this.$el, this.options); | |
this.glide = new Glide(this.$el, { | |
perView: 3, | |
gap: 12 | |
}).mount(); | |
this.updateNumberOfTweets(); | |
window.addEventListener("resize", () => { | |
this.updateNumberOfTweets(); | |
}); | |
}, | |
beforeDestroy() { | |
// this.slider.destroy(); | |
}, | |
methods: { | |
prev() { | |
this.glide.go("<"); | |
}, | |
next() { | |
this.glide.go(">"); | |
}, | |
linkify(text) { | |
return linkifyHtml(text); | |
}, | |
updateNumberOfTweets() { | |
if (window.outerWidth > 500 && window.outerWidth <= 1100) { | |
this.glide.update({ perView: 2.1 }); | |
} else if (window.outerWidth > 1100) { | |
this.glide.update({ perView: 3.1 }); | |
} else { | |
this.glide.update({ perView: 1.2 }); | |
} | |
} | |
} | |
}; | |
</script> | |
<template> | |
<div class="glide"> | |
<div class="glide__track" data-glide-el="track"> | |
<ul class="glide__slides pb-6"> | |
<li class="glide__slide" | |
v-for="tweet in tweets" | |
:key="tweet.id"> | |
<div class="py-6 px-4"> | |
<div class="p-6 rounded shadow-lg h-64 flex flex-col justify-between bg-white"> | |
<div> | |
<p v-html="linkify(tweet.text)"></p> | |
</div> | |
<div class="font-bold text-sm text-grey"> | |
{{ tweet.created_at.substring(0, 16) }} | |
</div> | |
</div> | |
</div> | |
</li> | |
</ul> | |
</div> | |
<button class="bg-white rounded-full shadow-lg hover:shadow-xl w-10 h-10 outline-none absolute flex items-center justify-center text-grey hover:text-purple z-10" style="right: 30px; top: 40%;" @click="next"> | |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 501.5 501.5" class="w-6 h-6 fill-current"><g><path d="M199.33 410.622l-55.77-55.508L247.425 250.75 143.56 146.384l55.77-55.507L358.44 250.75z"/></g></svg> | |
</button> | |
<div class="gradient-white-right w-24 md:w-48 pin-t pin-b pin-r absolute"></div> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The styles are using tailwind css classes. You can ignore the twitter code