Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 3, 2011 16:28
Show Gist options
  • Save Raynos/1427504 to your computer and use it in GitHub Desktop.
Save Raynos/1427504 to your computer and use it in GitHub Desktop.
Cleaning attempt
/**
* BarFoos Module (Layer 3)
* -----------------------------------------
* Box3D: This module handles the center box with help of CSS3 in 3D
*
* This code runs in strict mode (if supported by the environment).
* -----------------------------------------
* Author: Andreas Goebel
* Date: 2011-11-12
* Changed: 2011-11-12
*/
"use strict";
var BF = require("BF::main"),
destroyer = BF.destroyer,
sandbox = require("BF::sandbox"),
app = require("BF::app"),
$$ = sandbox.$;
var rootNode = $$("#box"),
xAngle = 35,
nodes = [],
yAngle = 0;
var Box3D = {
init: function _init() {
create3DBox();
bindDOMEvents();
initElements();
},
destroy: function _destroy() {
destroyer(nodes);
}
};
function create3DBox( ) {
creationData: [
[ 0, 0, 0 ],
[ 90, 0, 0 ],
[ 0, 90, 0 ],
[ 0, 180, 0],
[ 0, -90, 0],
[ -90, 0, 180]
].forEach(function _forEach( side ) {
nodes.push($$( '<div>', {
'class': 'boxFace',
'css': {
transform: 'rotateX(' + side[ 0 ] +
'deg) rotateY(' + side [ 1 ] +
'deg) translateZ(200px) rotate(' +
side[ 2 ] + 'deg)'
}
}).appendTo( rootNode ));
});
}
function bindDOMevents() {
rootNode
.on( 'mouseenter', '.boxFace', boxFaceMouseEnter)
.on( 'mouseleave', '.boxFace', boxFaceMouseLeave);
function boxFaceMouseEnter( e ) {
var $$this = $$( this );
$$this.stop( true ).animate({
opacity: 0.15
}, 600 );
}
function boxFaceMouseLeave( e ) {
var $$this = $$( this );
$$this.stop( true ).animate({
opacity: 1
}, 400 );
}
}
function initElements() {
rootNode.css({
transformStyle: 'preserve-3d'
}).animate({
opacity: 0.3
}, 3000, afterOpacity);
nodes.push(rootNode);
function afterOpacity() {
rootNode.animate({
transform: 'rotateX(' + xAngle + 'deg) rotateY(' + yAngle + 'deg)',
opacity: 0.9
}, 2000, boxRotate);
}
}
function boxRotate() {
xAngle = xAngle * -1;
yAngle += 340;
rootNode.animate({
transform: 'rotateX(' + xAngle + 'deg) rotateY(' + yAngle + 'deg)'
}, 20000, boxRotate, 'linear');
}
module.exports = Box3D;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment