Last active
August 29, 2015 14:07
-
-
Save turbodrive/3d84f8fcd965b14fb70e to your computer and use it in GitHub Desktop.
AE to CSS Workflow - Part 3 - Finalisation Javascript and enhancements.
This file contains hidden or 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
var easeInOutExpo = function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * Math.pow(2, 10 * (t - 1)) + b; | |
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; | |
}; | |
var getValueForProp = function(propName){ | |
if(globalCamProgression == parseInt(globalCamProgression)){ | |
return -targets3D[parseInt(globalCamProgression)][propName]; | |
}else{ | |
var t0 = Math.ceil(globalCamProgression-1); | |
var t1 = Math.ceil(globalCamProgression); | |
var t = (globalCamProgression-(parseInt(globalCamProgression))); | |
var b = targets3D[t0][propName]; | |
var c = targets3D[t1][propName]-b; | |
var d = 1; | |
return -easeInOutExpo(t,b,c,d); | |
} | |
}; |
This file contains hidden or 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
var jsonLoaded = function(jsonData) { | |
targetPositions = JSON.parse(jsonData); | |
// parse the JSON file | |
targets = targetPositions.targets; | |
// store the targets | |
nbrTargets = targets.length; | |
// get the number of pages | |
createScene(); | |
createTargets(); | |
addControls(); | |
} |
This file contains hidden or 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
var getPerspective = function (focalLength, viewportWidth, filmWidth){ | |
if(filmWidth === undefined) filmWidth = 36; | |
var cssPerspective = viewportWidth / (filmWidth/(focalLength)) | |
return cssPerspective; | |
} | |
var updatePerspective = function() { | |
var perspective = getPerspective(28,viewportWidth)+"px"; | |
stage.domElement.style.perspective = perspective ; | |
stage.domElement.style["-webkit-perspective"] = perspective ; | |
} |
This file contains hidden or 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
var updatePageScale = function(){ | |
var rX = viewportWidth/1280; | |
var rY = viewportHeight/720; | |
var scale = rX < rY ? rX : rY; | |
for(var i = 0; i < nbrTargets ;i++) { | |
targets3D[i].setScale(scale,scale,scale).update(); | |
} | |
} |
This file contains hidden or 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
var updatePageSize = function(){ | |
// pageContent | |
var pages = document.getElementsByClassName("page"); | |
var face; | |
var borderSize = 10; | |
for(var i = 0; i < nbrTargets ;i++) { | |
pages[i].style.width = viewportWidth + "px"; | |
pages[i].style.height = viewportHeight + "px"; | |
face = pages[i].getElementsByClassName("face")[0]; | |
face.style.width = (viewportWidth - (borderSize*2)) + "px"; | |
face.style.height = (viewportHeight - (borderSize*2)) + "px"; | |
//pages as sprites3D | |
targets3D[i].setRegistrationPoint(halfViewportWidth, halfViewportHeight ,0).update(); | |
} | |
} |
This file contains hidden or 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
var resizeWindowHandler = function(e) { | |
viewportWidth = window.innerWidth; | |
viewportHeight = window.innerHeight; | |
halfViewportWidth = viewportWidth>>1; | |
halfViewportHeight = viewportHeight>>1; | |
stage.domElement.style.lef = halfViewportWidth; | |
stage.domElement.style.top = halfViewportHeight; | |
stage.domElement.style["-webkit-transform-origin"] = String(Number(halfViewportWidth)) + "px " + String(Number(halfViewportHeight)) + "px"; | |
stage.domElement.style.width = viewportWidth + "px"; | |
stage.domElement.style.height = viewportHeight + "px"; | |
stage.setPosition(halfViewportWidth, halfViewportHeight, 0).update(); | |
var p = String(Number(-halfViewportWidth)) + "px " + String(Number(-halfViewportHeight)) + "px"; | |
stage.domElement.style["-webkit-perspective-origin"] = p; | |
stage.domElement.style["-moz-perspective-origin"] = p; | |
stage.domElement.style["perspective-origin"] = p; | |
interactContainer.setPosition(-halfViewportWidth, -halfViewportHeight, 0).update(); | |
} | |
// when the scene is created, manage the window resizing. | |
window.addEventListener("resize", resizeWindowHandler); | |
resizeWindowHandler(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment