Skip to content

Instantly share code, notes, and snippets.

@radislaw
Created July 3, 2018 09:03
Show Gist options
  • Select an option

  • Save radislaw/9aef927842411a27aa2767aa6cc9ab83 to your computer and use it in GitHub Desktop.

Select an option

Save radislaw/9aef927842411a27aa2767aa6cc9ab83 to your computer and use it in GitHub Desktop.
hide buttons in first and last slide in swiper
let productShowcase = this.initSwiper('.product-showcase', {
slidesPerView: 3,
onInit(e) {
if(e.isBeginning) {
e.prevButton[0].style.display = 'none'
}
},
})
productShowcase.forEach((item) => {
// hide buttons in first and last slide
item.on('progress', ((e) => {
if(e.isBeginning) {
e.prevButton[0].style.display = 'none'
} else if(e.isEnd) {
e.nextButton[0].style.display = 'none'
} else {
e.prevButton[0].style.display = 'block'
e.nextButton[0].style.display = 'block'
}
}))
// remove arrows and destroy slider when num of slides per view <= num of total slides
if(item.slides) {
if(item.slides.length < numOfSlides) {
item.destroy(false)
item.nextButton[0].parentNode.removeChild(item.nextButton[0])
item.prevButton[0].parentNode.removeChild(item.prevButton[0])
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment