I’m setting up an image slider with thumbnail slider using this plugin in React.js: http://flexslider.woothemes.com/thumbnail-slider.html
If I add the <li>
s statically it works perfectly fine:
JavaScript
x
9
1
<div id="carousel" class="flexslider">
2
<ul class="slides">
3
<li><img src="slide1.jpg" /></li>
4
<li><img src="slide2.jpg" /></li>
5
<li><img src="slide3.jpg" /></li>
6
<li><img src="slide4.jpg" /></li>
7
</ul>
8
</div>
9
However if I try to load the content dynamically, the inline styles that are dynamically calculated and added by the plugin code won’t be added to both ul
and li
elements (i.e width: 210px; margin-right: 5px; float: left; display: block;
)
This is how I do it:
JavaScript
1
23
23
1
render() {
2
3
if(this.props.data){
4
var projects = this.props.data.projects.map(function(projects){
5
var projectImage = 'images/portfolio/'+projects.image;
6
7
return <li key={projects.title}>
8
<img alt={projects.title} src={projectImage} />
9
</li>
10
})
11
}
12
13
return (
14
<section id="portfolio">
15
<div id="carousel" class="flexslider">
16
<ul class="slides">
17
{projects}
18
</ul>
19
</div>
20
</section>
21
);
22
}
23
Advertisement
Answer
According to the link that you gave, the plugin requires initialization. Where are you doing your initialization?
I would recommend doing the initialization in the componentDidMount
life cycle method. This is because when that code runs the <li>
would have already been in DOM.