Just a few lines of code and we have a MIDI-keyboardish thingie full of colored square keys to click:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colors = [ '#CCDDBB', '#99CC66', '#88AA66', '#AADDCC' | |
'#66AAAA', '#559999', '#FFFFDD', '#FF9922' | |
'#DD8822', '#AACCDD', '#5599CC', '#4477AA' ] | |
nextSquareHtml = (color) -> """ | |
<div style="background: #{color}; border: 1px solid grey; | |
height: 30px; width: 30px; margin: 5px; float: left"></div>""" | |
grow = (square) -> | |
square.animate(height: 60, 200).animate height: 30 | |
for c in colors | |
$j(nextSquareHtml c) | |
.appendTo( $j '#keyboard' ) | |
.click -> grow $j(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
squares = ( $j(nextSquareHtml c) for c in colors ) | |
for s,i in squares | |
s.appendTo( $j '#keyboard' ) #assembling the keyboard | |
.click -> | |
grow $j(this), 7 | |
#attach the next one, make it circular | |
.data('next', squares[ (i+1) % squares.length ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grow = (square, i) -> | |
if i>0 and not square.is ':animated' | |
square.animate height: 60, 200, | |
-> grow square.data('next'), i-1 | |
.animate height: 30 |
Source code links: