Skip to content

Commit

Permalink
use spritesheet for player controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Brooke committed Mar 3, 2014
1 parent cf42a95 commit e6c31e0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 62 deletions.
Binary file added public/images/controls-sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/index.html
Expand Up @@ -48,9 +48,9 @@
<li id="8">Driven</li>
</ul>
<div class="controls">
<div id="prev"></div>
<div id="play"></div>
<div id="next"></div>
<i id="prev" class="sprite sprite-prev"></i>
<i id="play" class="sprite sprite-play"></i>
<i id="next" class="sprite sprite-next"></i>
</div>
</div>

Expand Down
8 changes: 4 additions & 4 deletions public/scripts/main.js
Expand Up @@ -104,16 +104,16 @@
} else if (track.ended) {
active.className = '';
// reset back to first song, wait to play
document.getElementById(1).className = 'active';
playButton.className = '';
document.getElementById('1').className = 'active';
playButton.className = 'sprite sprite-play';
}
}

function togglePlayback(e) {
if (e) e.preventDefault();
var active = document.getElementsByClassName('active')[0];
~active.className.indexOf('playing') ? active.className = 'active' : active.className = 'active playing';
playButton.className ? playButton.className = '' : playButton.className = 'pause';
playButton.className == 'sprite sprite-pause' ? playButton.className = 'sprite sprite-play' : playButton.className = 'sprite sprite-pause';
track.paused || track.ended ? track.play() : track.pause();
}

Expand All @@ -133,7 +133,7 @@
var src = audioFolder + num + ext;
if (~track.src.indexOf(src)) return;
track.src = src;
playButton.className = 'pause';
playButton.className = 'sprite sprite-pause';
waveBase.src = imgFolder + num + '-bg.png';
waveCover.style.width = 0;
waveCover.style.backgroundImage = 'url(' + imgFolder + num + '.png)';
Expand Down
116 changes: 61 additions & 55 deletions public/styles/main.css
Expand Up @@ -76,61 +76,6 @@ li a {
background: url(../images/indicator.gif);
}

.controls {
margin: 0 auto;
width: 300px;
text-align: center;
}

.controls div {
cursor: pointer;
display: inline-block;
}

#play {
margin-bottom: -5px;
height: 60px;
width: 150px;
}

#play {
background: url(../images/play.png) 55% no-repeat;
background-size: contain;
}

#play.pause {
background: url(../images/pause.png) center no-repeat;
background-size: contain;
opacity: 0.85;
transition: opacity 0.2s;
}

#play.pause:hover {
opacity: 1;
}

#prev, #next {
height: 45px;
width: 70px;
opacity: 0.85;
transition: opacity 0.2s;
}

#prev:hover, #next:hover {
opacity: 1.0;
transition: opacity 0.2s;
}

#prev {
background-image: url(../images/prev.png);
background-size: contain;
}

#next {
background-image: url(../images/next.png);
background-size: contain;
}

.links {
text-align: right;
position: absolute;
Expand Down Expand Up @@ -253,4 +198,65 @@ a {
-moz-transition: color 0.2s;
-webkit-transition: color 0.2s;
transition: color 0.2s;
}

.sprite {
background-image: url(../images/controls-sprite.png);
background-repeat: no-repeat;
}

.controls {
margin: 0 auto;
width: 300px;
text-align: center;
}

.controls i {
cursor: pointer;
display: inline-block;
}

#play {
margin-bottom: -15px;
margin-left: 20px;
margin-right: 15px;
width: 90px;
height: 80px;
background-position: -86px -1px;
}

#play.sprite-pause {
margin-left: 22px;
margin-right: 20px;
margin-bottom: -17px;
opacity: 0.9;
opacity: 0.9;
transition: opacity 0.2s;
width: 83px;
height: 82px;
background-position: -1px -46px;
}

#play.sprite-pause:hover {
opacity: 1;
}

#prev, #next {
opacity: 0.9;
transition: opacity 0.2s;
width: 69px;
height: 43px;
}

#prev:hover, #next:hover {
opacity: 1.0;
transition: opacity 0.2s;
}

#prev {
background-position: -86px -83px;
}

#next {
background-position: -1px -1px;
}

0 comments on commit e6c31e0

Please sign in to comment.