first commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
jQuery(document).ready(function($){
|
||||
var timelineBlocks = $('.eael-content-timeline-block'),
|
||||
offset = 0.8;
|
||||
|
||||
//hide timeline blocks which are outside the viewport
|
||||
hideBlocks(timelineBlocks, offset);
|
||||
|
||||
//on scolling, show/animate timeline blocks when enter the viewport
|
||||
$(window).on('scroll', function(){
|
||||
(!window.requestAnimationFrame)
|
||||
? setTimeout(function(){ showBlocks(timelineBlocks, offset); }, 100)
|
||||
: window.requestAnimationFrame(function(){ showBlocks(timelineBlocks, offset); });
|
||||
});
|
||||
|
||||
function hideBlocks(blocks, offset) {
|
||||
blocks.each(function(){
|
||||
( $(this).offset().top > $(window).scrollTop()+$(window).height()*offset ) && $(this).find('.eael-content-timeline-img, .eael-content-timeline-content').addClass('is-hidden');
|
||||
});
|
||||
}
|
||||
|
||||
function showBlocks(blocks, offset) {
|
||||
blocks.each(function(){
|
||||
( $(this).offset().top <= $(window).scrollTop()+$(window).height()*offset && $(this).find('.eael-content-timeline-img').hasClass('is-hidden') ) && $(this).find('.eael-content-timeline-img, .eael-content-timeline-content').removeClass('is-hidden').addClass('');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Timeline Animation Script
|
||||
*/
|
||||
var getElementsInArea = (function(docElm){
|
||||
var viewportHeight = docElm.clientHeight;
|
||||
|
||||
return function(e, opts){
|
||||
var found = [], i;
|
||||
|
||||
if( e && e.type == 'resize' )
|
||||
viewportHeight = docElm.clientHeight;
|
||||
|
||||
for( i = opts.elements.length; i--; ){
|
||||
var elm = opts.elements[i],
|
||||
pos = elm.getBoundingClientRect(),
|
||||
topPerc = pos.top / viewportHeight * 100,
|
||||
bottomPerc = pos.bottom / viewportHeight * 100,
|
||||
middle = (topPerc + bottomPerc)/2,
|
||||
inViewport = middle > opts.zone[1] &&
|
||||
middle < (100-opts.zone[1]);
|
||||
|
||||
elm.classList.toggle(opts.markedClass, inViewport);
|
||||
|
||||
if( inViewport )
|
||||
found.push(elm);
|
||||
}
|
||||
};
|
||||
})(document.documentElement);
|
||||
|
||||
/**
|
||||
* Use Case
|
||||
*/
|
||||
window.addEventListener('scroll', f)
|
||||
window.addEventListener('resize', f)
|
||||
|
||||
function f(e){
|
||||
getElementsInArea(e, {
|
||||
elements : document.querySelectorAll('.eael-content-timeline-block'),
|
||||
markedClass : 'eael-highlight',
|
||||
zone : [15, 15] // percentage distance from top & bottom
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
jQuery(document).ready(function(e){var n=e(".eael-content-timeline-block");function t(n,t){n.each(function(){e(this).offset().top<=e(window).scrollTop()+e(window).height()*t&&e(this).find(".eael-content-timeline-img").hasClass("is-hidden")&&e(this).find(".eael-content-timeline-img, .eael-content-timeline-content").removeClass("is-hidden").addClass("")})}!function(n,t){n.each(function(){e(this).offset().top>e(window).scrollTop()+e(window).height()*t&&e(this).find(".eael-content-timeline-img, .eael-content-timeline-content").addClass("is-hidden")})}(n,.8),e(window).on("scroll",function(){window.requestAnimationFrame?window.requestAnimationFrame(function(){t(n,.8)}):setTimeout(function(){t(n,.8)},100)});var i,o,l=(i=document.documentElement,o=i.clientHeight,function(e,n){var t,l=[];for(e&&"resize"==e.type&&(o=i.clientHeight),t=n.elements.length;t--;){var s=n.elements[t],c=s.getBoundingClientRect(),d=(c.top/o*100+c.bottom/o*100)/2,a=d>n.zone[1]&&d<100-n.zone[1];s.classList.toggle(n.markedClass,a),a&&l.push(s)}});function s(e){l(e,{elements:document.querySelectorAll(".eael-content-timeline-block"),markedClass:"eael-highlight",zone:[15,15]})}window.addEventListener("scroll",s),window.addEventListener("resize",s)});
|
||||
Reference in New Issue
Block a user