Skip to content

Commit

Permalink
Create dlwWebCompLib.js
Browse files Browse the repository at this point in the history
Create dlwWebCompLib.js
  • Loading branch information
conradsbrain authored May 4, 2023
1 parent 092d20d commit 896dbb8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dlwWebCompLib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* web component for Hero Banner Image */
const heroElement = document.querySelector("hero-banner");
const hbHeight = heroElement.dataset.imgHeight;
const hbUrl = heroElement.dataset.imgUrl;
const hbPosition = heroElement.dataset.imgPosition;
heroElement.style.setProperty("--bg-hero-banner-image-height", hbHeight + "px");
heroElement.style.setProperty("--bg-hero-banner-image-url", "url("+hbUrl+")");
heroElement.style.setProperty("--bg-hero-banner-image-position", hbPosition);

const templateHeroBanner = document.createElement('template');
templateHeroBanner.innerHTML = `
<style>
.hero-banner-image {
height: var(--bg-hero-banner-image-height);
background-image: var(--bg-hero-banner-image-url);
background-position: var(--bg-hero-banner-image-position);
}
</style>
<div class="hero-banner-image"></div>
`

class HeroBanner extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: 'open' })
shadow.append(templateHeroBanner.content.cloneNode(true));
}
}
customElements.define('hero-banner', HeroBanner);

0 comments on commit 896dbb8

Please sign in to comment.