Skip to content

Instantly share code, notes, and snippets.

@kylerberry
Last active January 6, 2023 08:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylerberry/51cf28565e434de410d6ebd337a2f962 to your computer and use it in GitHub Desktop.
Save kylerberry/51cf28565e434de410d6ebd337a2f962 to your computer and use it in GitHub Desktop.
an example of using GlideJs with LitElement
import { LitElement, css, html, unsafeCSS} from 'lit-element'
import Glide from '@glidejs/glide'
import coreCSS from '../../node_modules/@glidejs/glide/dist/css/glide.core.min.css'
class ContentSlider extends LitElement {
firstUpdated() {
this.root = this.shadowRoot.querySelector('.glide')
new Glide(this.root).mount()
}
static get styles() {
return css`
${unsafeCSS(coreCSS)}
`
}
renderSlides() {
let slides = []
for(let i = 0; i < this.children.length; i++) {
slides.push(html`<li class="glide__slide"><slot name="slide${i+1}"></slot></li>`)
}
return slides
}
render() {
return html`
<div class="glide">
<div data-glide-el="track" class="glide__track">
<ul class="glide__slides">
${this.renderSlides()}
</ul>
</div>
</div>
`
}
}
window.customElements.define('content-slider', ContentSlider)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment