Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ImageBackground extends HTMLElement {
- createdCallback() {
- let src = this.hasAttribute('src') ? this.getAttribute('src') : '/static/images/user.png'
- let className = `img-bg ${this.hasAttribute('className') ? this.getAttribute('className') : ''}`
- let isLazy = this.getAttribute('lazy') !== false
- const slotContent = document.createElement('slot')
- slotContent.setAttribute('name', 'slot-content')
- const wrapper = document.createElement('div')
- wrapper.appendChild(slotContent)
- wrapper.style.backgroundImage = `url("${src}")`
- wrapper.style.backgroundSize = 'cover'
- wrapper.style.backgroundPosition = 'center'
- wrapper.style.height = '300px'
- wrapper.setAttribute('class', className)
- this.createShadowRoot().appendChild(wrapper)
- }
- }
- document.registerElement('img-bg', ImageBackground)
- img-bg(src="/static/images/email.svg")
- p(slot="slot-content") cek
Add Comment
Please, Sign In to add comment