Skip to content

Commit 54c0f79

Browse files
committed
Flux - 24 - Playing Videos on Mouseover
1 parent 56668a1 commit 54c0f79

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

imgur-client/sass/image-preview.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66
width: 200px;
77
display: inline-block;
88
}
9+
10+
video {
11+
height: 200px;
12+
width: 200px;
13+
vertical-align: middle;
14+
background-color: black;
15+
}
916
}
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
var React = require('react');
22

33
module.exports = React.createClass({
4+
getInitialState: function() {
5+
return {
6+
hovering: false
7+
}
8+
},
49
render: function() {
5-
return <div className="image-preview">
6-
{this.image()}
10+
return <div
11+
className="image-preview"
12+
onMouseEnter={this.handleMouseEnter}
13+
onMouseLeave={this.handleMouseLeave}
14+
>
15+
{this.props.animated && this.state.hovering ? this.video() : this.image()}
716
</div>
817
},
918
image: function() {
1019
var link = 'http://i.imgur.com/' + this.props.id + 'h.jpg';
1120

1221
return <img src={link} />
22+
},
23+
video: function() {
24+
return <div>
25+
<video preload='auto' autoPlay='autoplay' loop='loop' webkit-playsinline>
26+
<source src={this.props.mp4} type='video/mp4'></source>
27+
</video>
28+
</div>
29+
},
30+
handleMouseEnter: function() {
31+
this.setState({hovering: true});
32+
},
33+
handleMouseLeave: function() {
34+
this.setState({hovering: false});
1335
}
1436
});

0 commit comments

Comments
 (0)