-
-
Save kylerberry/51cf28565e434de410d6ebd337a2f962 to your computer and use it in GitHub Desktop.
an example of using GlideJs with LitElement
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
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