Famo.us Paper Buttons
An experiment in replicating the Polymer paper button effect
by Clay Smith
HTML
<script src="http://famousco.de/fiddle/famousBox.js"></script>
JavaScript
define('RippleSurface', function (require, exports, module) {
var Surface = require('famous/core/Surface');
var Timer = require('famous/utilities/Timer');
var Transitionable = require('famous/transitions/Transitionable');
// Extend the button surface to tap into .render()
function RippleSurface(options) {
Surface.apply(this, arguments);
this.gradientOpacity = new Transitionable(0);
this.gradientRadius = new Transitionable(0);
// Use light or dark gradient?
if (options.tint === 'light') {
// radiate light to dark
this.firstStop = '255,255,255';
} else {
// radiate dark to light by default
this.firstStop = '0,0,0';
}
// Hold on to offsetX/Y throughout render loop during transition
this.offsetX = 0;
this.offsetY = 0;
this.on('mousedown', this.ripple);
this.on('mouseup', this.smooth);
this.on('mouseleave', this.smooth);
this.on('deploy', this.postDeploy);
}
RippleSurface.prototype = Object.create(Surface.prototype);
RippleSurface.prototype.constructor = RippleSurface;
RippleSurface.prototype.postDeploy = function () {
// Have to do this here in order to account for undefined or boolean sizes
var width = (typeof this.size[0] === 'number') ? this.size[0] : this._currTarget.clientWidth;
var height = (typeof this.size[1] === 'number') ? this.size[1] : this._currTarget.clientHeight;
// Maximum radius large enough to cover the surface from corner to corner
this.gradientMaxRadius = Math.round(Math.sqrt(width * width + height * height));
// Based on "feels good" numbers of growing 100px in 300 milliseconds
this.gradientDuration = (this.gradientMaxRadius / 100) * 300;
};
RippleSurface.prototype.render = function () {
var gradientOpacity = this.gradientOpacity.get();
var...