Skip to content

Commit 11229ca

Browse files
committed
adjusted hero slide count in home based on window width
1 parent 942c386 commit 11229ca

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/components/Hero/Hero.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@
2323
color:#FFF;
2424
font-family: Helvetica, Arial, sans-serif;
2525
font-weight:bold;
26-
font-size:36px;
26+
font-size:16px;
2727
position: absolute;
2828
margin:auto;
29-
padding:10px;
29+
padding:20px 10px;
3030
z-index: 10;
31-
display: inline-table;
32-
@media (min-width: 768px) {
33-
display:block;
34-
}
31+
3532
}
3633

3734
}

src/containers/HomeContainer/HomeContainer.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class HomeContainer extends Component {
2020
this.state = {
2121
loading: true,
2222
featuredChars: [],
23-
error: false
23+
error: false,
24+
heroSlideCount: 3
2425
}
2526
}
2627

2728
componentWillMount() {
2829
Featured.map((id => this.handleFetchRelated(id)))
30+
window.addEventListener('resize', this.adjustSlideNumber.bind(this))
2931
}
3032

3133
handleFetchRelated(id) {
@@ -42,16 +44,25 @@ class HomeContainer extends Component {
4244
fetchRequest.catch(error => this.setState({ error : true }))
4345
}
4446

47+
adjustSlideNumber() {
48+
if (window.innerWidth < 768) {
49+
this.setState({heroSlideCount: 1})
50+
} else {
51+
this.setState({heroSlideCount: 3})
52+
}
53+
}
54+
4555
render() {
46-
const {featuredChars, error } = this.state
56+
57+
const {featuredChars, error, heroSlideCount } = this.state
4758
return (
4859
<div>
4960
<Container classNames={'red-stripe-bg'}>
5061
<Row classNames={'ml15 mr15'}>
5162
{featuredChars.length !== Featured.length ?
5263
!error ? <Loader /> : <div className='alert alert-danger' role='alert'>Error Fetching data</div>
5364
:
54-
<Slider slidesToShow={1} slidesToScroll={1} lazy dots={true} draggable={false} arrows={false}>
65+
<Slider slidesToShow={this.state.heroSlideCount} slidesToScroll={this.state.heroSlideCount} lazy dots={true} draggable={false} arrows={false}>
5566
{featuredChars.map(({id, name, thumbnail, description}, i) => (
5667
<div key={i}>
5768
<Link to={`/characters/${id}`}>

0 commit comments

Comments
 (0)