MetteT
November 26, 2022, 11:11am
1
Is there a way to make these navigation/slider buttons on mobile show as dots instead of numbers with arrows?
They are on all my milticolumn sections, my collections and my product images/media.
URL: https://teefiti.dk/products/stella-langaermet-top Code: Teefiti2022
Hi @MetteT
After looking at your store, I assume you’re using the Dawn theme. So a note that the solution below is for the Dawn theme and might not work for other themes. Please follow these steps:
Navigate to Online store > Themes > Edit code
Find the file “multicolumn.liquid” and find the code block below:
Then change these code into this:
{%- for block in section.blocks -%}
{%- endfor -%}
Find global.js file and find these code
It’s about 80 lines of code starting from “class SliderComponent extends HTMLElement.” Then change all of them into these codes.
class SliderComponent extends HTMLElement {
constructor() {
super();
this.slider = this.querySelector('[id^="Slider-"]');
this.sliderItems = this.querySelectorAll('[id^="Slide-"]');
this.enableSliderLooping = false;
this.currentPageElement = this.querySelector('.slider-counter--current');
this.pageTotalElement = this.querySelector('.slider-counter--total');
this.prevButton = this.querySelector('button[name="previous"]');
this.nextButton = this.querySelector('button[name="next"]');
if (!this.slider || !this.nextButton) return;
this.initPages();
const resizeObserver = new ResizeObserver(entries => this.initPages());
resizeObserver.observe(this.slider);
this.slider.addEventListener('scroll', this.update.bind(this));
this.prevButton.addEventListener('click', this.onButtonClick.bind(this));
this.nextButton.addEventListener('click', this.onButtonClick.bind(this));
this.sliderControlWrapper = this.querySelector('.slider-buttons');
if (!this.sliderControlWrapper) return;
this.sliderFirstItemNode = this.slider.querySelector('.slideshow__slide');
this.sliderControlLinksArray = Array.from(this.sliderControlWrapper.querySelectorAll('.slider-counter__link'));
this.sliderControlLinksArray.forEach(link => link.addEventListener('click', this.linkToSlide.bind(this)));
}
initPages() {
this.sliderItemsToShow = Array.from(this.sliderItems).filter(element => element.clientWidth > 0);
if (this.sliderItemsToShow.length < 2) return;
this.sliderItemOffset = this.sliderItemsToShow[1].offsetLeft - this.sliderItemsToShow[0].offsetLeft;
this.slidesPerPage = Math.floor(this.slider.clientWidth / this.sliderItemOffset);
this.totalPages = this.sliderItemsToShow.length - this.slidesPerPage + 1;
this.update();
}
resetPages() {
this.sliderItems = this.querySelectorAll('[id^="Slide-"]');
this.initPages();
}
update() {
const previousPage = this.currentPage;
this.currentPage = Math.round(this.slider.scrollLeft / this.sliderItemOffset) + 1;
if (this.currentPageElement && this.pageTotalElement) {
this.currentPageElement.textContent = this.currentPage;
this.pageTotalElement.textContent = this.totalPages;
}
if (this.currentPage != previousPage) {
this.dispatchEvent(new CustomEvent('slideChanged', { detail: {
currentPage: this.currentPage,
currentElement: this.sliderItemsToShow[this.currentPage - 1]
}}));
}
if (this.enableSliderLooping) return;
if (this.isSlideVisible(this.sliderItemsToShow[0])) {
this.prevButton.setAttribute('disabled', 'disabled');
} else {
this.prevButton.removeAttribute('disabled');
}
if (this.isSlideVisible(this.sliderItemsToShow[this.sliderItemsToShow.length - 1])) {
this.nextButton.setAttribute('disabled', 'disabled');
} else {
this.nextButton.removeAttribute('disabled');
}
this.sliderControlButtons = this.querySelectorAll('.slider-counter__link');
this.prevButton.removeAttribute('disabled');
if (!this.sliderControlButtons.length) return;
this.sliderControlButtons.forEach(link => {
link.classList.remove('slider-counter__link--active');
link.removeAttribute('aria-current');
});
this.sliderControlButtons[this.currentPage - 1].classList.add('slider-counter__link--active');
this.sliderControlButtons[this.currentPage - 1].setAttribute('aria-current', true);
}
isSlideVisible(element, offset = 0) {
const lastVisibleSlide = this.slider.clientWidth + this.slider.scrollLeft - offset;
return (element.offsetLeft + element.clientWidth) <= lastVisibleSlide && element.offsetLeft >= this.slider.scrollLeft;
}
onButtonClick(event) {
event.preventDefault();
const step = event.currentTarget.dataset.step || 1;
this.slideScrollPosition = event.currentTarget.name === 'next' ? this.slider.scrollLeft + (step * this.sliderItemOffset) : this.slider.scrollLeft - (step * this.sliderItemOffset);
this.slider.scrollTo({
left: this.slideScrollPosition
});
}
linkToSlide(event) {
event.preventDefault();
const slideScrollPosition = this.slider.scrollLeft + this.slider.clientWidth * (this.sliderControlLinksArray.indexOf(event.currentTarget) + 1 - this.currentPage);
this.slider.scrollTo({
left: slideScrollPosition
});
}
}
Please let me know if it works for you by giving us a like or marking it as a solution.
Ujjaval
November 28, 2022, 7:25am
3
@MetteT
In your mobile view
$('.responsive').slick({
dots: true,
infinite: false,
speed: 300,
slidesToShow: 1, << set default for 1200px onward
slidesToScroll: 1,
responsive: [
{
breakpoint: 1024, << for desktop width 992px
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true
}
},
{
breakpoint: 600, << for tablet
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 480, << here's your mobile
settings: {
slidesToShow: 3,
slidesToScroll: 3,
dots:true,
arrows:false
}
}]});
As you can see last one responsive js for mobile there you just add dots: true and arrows:false . So, your problem will be solve .(You can refer above as example)
MetteT
November 28, 2022, 9:44am
4
@BSS-Commerce This unfortunately didnt work, even though i do use the Dawn theme, but i am on an older version of the theme. I cant upgrade though due to costum coding, which i have a lot of. It did remove the numbers inbetween the arrows on the multicolum section though.
MetteT
November 28, 2022, 9:45am
5
@Ujjaval Where is this code located?
Ujjaval
November 28, 2022, 9:50am
6
@MetteT in your custom.js where you put that slider js.
MetteT
November 28, 2022, 10:10am
7
@Ujjaval I dont have anything called custom.js? where i put what slider js? What @BSS-Commerce wrote about or?