The slider doesn't display and work properly on first display
See original GitHub issueHi
First of all, check my live demo https://ui.mofect.com/moblog the top slider doesn’t display properly, I have set slidesPerView to 2, but it only displays 1 and can’t be scrolled. But when I resize the window size, it works like a charm.
I have read this similar issue https://github.com/kidjp85/react-id-swiper/issues/185 but no solution for me. Here are my codes:
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import Swiper from 'react-id-swiper';
import SliderItem from '../../components/slider-dom';
import { Pagination } from 'swiper/dist/js/swiper.esm'
/* SlideShow */
class Slider extends Component{
constructor(props){
super(props);
this.state = {
data: [],
}
}
componentDidMount() {
this.loadSlider();
}
loadSlider = () => {
const { data } = this.state;
const url = `https://xxxxxxxxxxx/`;
fetch(url)
.then((response) => {
return response.json()
})
.then(json => {
this.setState({
data: json,
});
})
.catch(function() {
});
};
loop = () => {
let loop = [];
this.state.data.length > 0 && this.state.data.map((slide, i) => {
loop.push(
<SliderItem
key={ i }
id={ slide.id }
postType={ slide.post_type }
postID={ slide.post_id }
pageID={ slide.page_id }
productID={ slide.product_id }
title={ slide.title }
image={ slide.image }
description={ slide.description }
/>
);
});
return loop;
}
render() {
const params = {
slidesPerView: 2,
loop: true,
spaceBetween: 10,
modules: [Pagination],
shouldSwiperUpdate: true,
rebuildOnUpdate: true,
pagination: {
el: '.swiper-pagination',
type: 'bullets',
clickable: true
}
}
return(
<div className="mo-slider">
{ this.state.data &&
<Swiper { ...params} >
{ this.loop() }
</Swiper>
}
</div>
);
}
}
export default Slider;
Anything I missed?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Top 5 Reasons Why WordPress Slider is Not Working in ...
WordPress owners often complain about improper working sliders or carousels, WordPress images not displaying properly, and poor loading ...
Read more >WordPress Slider Not Working? Here's How to Fix It
Is your WordPress slider not displaying images? When your WordPress slider shows a progress bar and images are not appearing, it simply means ......
Read more >First slide in HTML Slider not displaying upon initial page load
My issue, is that when the page is first loaded, the first slide does not display at all. It is not until the...
Read more >Does not display properly on mobile | WordPress.org
Our slider has a rule, that a slide's height is at least as big as the height of your layers, margins and paddings...
Read more >Slider Revolution Won't Load First Slide - Support - Themeco
The slider loads fine on desktop, but on mobile or tablets, it just shows a loading icon. I have deactivated all my plugins...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone that is still searching for the solution, just make sure the length of the array of items is bigger than 0, here is how it is solved in one of the issues:https://github.com/kidjp85/react-id-swiper/issues/185
I think here is the issue
You should set the condition to
this.state.data.length > 1