Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
snippet of code working with skrollr to stop a Adobe Edge Composition at a defined timeline according to its percentage seen in viewport
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