Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 1x 4x 4x 4x 4x 4x 4x 4x 4x 1x 2x 2x 6x 1x 5x 8x 1x 1x | window.customElements.define('h-content-loader', class extends HTMLElement {
constructor() {
super()
const shadowRoot = this.attachShadow({ mode: 'open' })
shadowRoot.appendChild(this.generateTemplate().content.cloneNode(true))
this.$loader = this.shadowRoot.querySelector('div.content')
}
generateTemplate() {
const template = document.createElement('template')
template.innerHTML = `
<style>
.content {
background-color: var(--background, transparent);
margin: 0;
position: relative;
}
.loader {
align-items: center;
background-color: var(--background, transparent);
display: inline-flex;
height: 100%;
justify-content: center;
left: 0;
position: absolute;
top: 0;
transition: transform .2s ease-out;
visibility: hidden;
width: 100%;
z-index: 9999;
}
.dual-ring {
animation: dual-ring 1.2s linear infinite;
content: " ";
display: block;
border: 5px solid var(--on-background, #000);
border-left-color: transparent;
border-radius: 50%;
border-right-color: transparent;
height: 46px;
margin: 1px;
transition: transform .2s ease-out;
width: 46px;
}
@keyframes dual-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.loader:hover {
transform: scale(1.2);
}
.content.is-loading .loader {
visibility: visible;
min-height: 70px;
}
.content.is-loading slot {
visibility: hidden;
}
</style>
<div class="content">
<div class="loader">
<div class="dual-ring"></div>
</div>
<slot></slot>
</div>
`
return template
}
connectedCallback() {
this._render()
}
static get observedAttributes() {
return ['data-loading']
}
attributeChangedCallback(attr, oldValue, newValue) {
Eif (oldValue !== newValue) {
this._render()
}
}
_render() {
if (this.isLoading()) {
this.$loader.classList.add('is-loading')
} else {
this.$loader.classList.remove('is-loading')
}
}
isLoading() {
return this.getAttribute('data-loading') === 'true'
}
loading() {
this.dataset.loading = true
}
done() {
this.dataset.loading = false
}
})
|