Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Last active February 3, 2023 17:23
Show Gist options
  • Select an option

  • Save steveosoule/a2c2c16fcbfbf0cdc3c47bf2b70e5472 to your computer and use it in GitHub Desktop.

Select an option

Save steveosoule/a2c2c16fcbfbf0cdc3c47bf2b70e5472 to your computer and use it in GitHub Desktop.
Miva - MMX Hero Slider Manipulations
// Add a new mmx-hero slide after the first slide
const slider = document.getElementById('mmx-hero-slider__mmx_heroslider');
const firstSlide = slider.querySelector('[slot="hero_slide"]');
const newSlideHTML = /*html*/`
<mmx-hero
slot="hero_slide"
data-href="#foo"
data-heading="This is the heading!"
data-body="this is the body text"
data-content-location="center"
data-align="center"
data-overlay-bg="color"
data-overlay-bg-color="black"
data-content-theme="dark"
>
</mmx-hero>
`;
firstSlide.insertAdjacentHTML('afterend', newSlideHTML);
// Add a new mmx-hero slide with custom slotted content
const slider = document.getElementById('mmx-hero-slider__mmx_heroslider');
const firstSlide = slider.querySelector('[slot="hero_slide"]');
const newSlideHTML = /*html*/`
<mmx-hero slot="hero_slide">
<div slot="content">Custom Banner</div>
</mmx-hero>
`;
firstSlide.insertAdjacentHTML('afterend', newSlideHTML);
// Replace second slide with a new mmx-hero slide and custom slotted content
const slider = document.getElementById('mmx-hero-slider__mmx_heroslider');
const secondSlide = slider.querySelector('[slot="hero_slide"]:nth-child(2)');
const newSlideHTML = /*html*/`
<mmx-hero slot="hero_slide">
<div slot="content">Custom Banner</div>
</mmx-hero>
`;
secondSlide.outerHTML = newSlideHTML;
// Add any custom HTML as the second slide
const slider = document.getElementById('mmx-hero-slider__mmx_heroslider');
const firstSlide = slider.querySelector('[slot="hero_slide"]');
const newSlideHTML = /*html*/`<div slot="hero_slide">Custom Banner</div>`;
firstSlide.insertAdjacentHTML('afterend', newSlideHTML);
// Replace the second slide with any custom HTML
const slider = document.getElementById('mmx-hero-slider__mmx_heroslider');
const secondSlide = slider.querySelector('[slot="hero_slide"]:nth-child(2)');
const newSlideHTML = /*html*/`
<div slot="hero_slide">Custom Banner</div>
`;
secondSlide.outerHTML = newSlideHTML;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment