Created
January 24, 2014 14:32
-
-
Save ibaaj/8598370 to your computer and use it in GitHub Desktop.
snippet of code working with skrollr to stop a Adobe Edge Composition at a defined timeline according to its percentage seen in viewport
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
function percentageSeen (id) { | |
var $element = $('#'+id), $win = $(window),viewportHeight = $(window).height(), | |
scrollTop = $win.scrollTop(), | |
elementOffsetTop = $element.offset().top, | |
elementHeight = $element.height(); | |
if (elementOffsetTop > (scrollTop + viewportHeight)) { | |
return 0; | |
} else if ((elementOffsetTop + elementHeight) < scrollTop) { | |
return 100; | |
} else { | |
var distance = (scrollTop + viewportHeight) - elementOffsetTop; | |
var percentage = distance / ((viewportHeight + elementHeight) / 100); | |
percentage = Math.ceil(percentage); | |
return percentage; | |
} | |
} | |
var p; | |
var mySkroll = skrollr.init({ | |
forceHeight: false, | |
render: function(data) { | |
p = percentageSeen('id'); // div id, the container of the Edge composition | |
if(p > 0 && p < 100) | |
{ | |
AdobeEdge.bootstrapCallback(function(compId) { | |
comp = AdobeEdge.getComposition("EdgeCompostionId").getStage(); // EdgeCompositionId is the composition name | |
comp.stop(p*100); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment