Total Complexity | 9 |
Complexity/F | 1.13 |
Lines of Code | 26 |
Function Count | 8 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | jQuery(document).ready(function ($) { |
||
2 | var timelineBlocks = $('.cd-timeline-block'), |
||
3 | offset = 0.8; |
||
4 | |||
5 | // hide timeline blocks which are outside the viewport |
||
6 | hideBlocks(timelineBlocks, offset); |
||
7 | |||
8 | // on scolling, show/animate timeline blocks when enter the viewport |
||
9 | $(window).on('scroll', function () { |
||
10 | (!window.requestAnimationFrame) |
||
11 | ? setTimeout(function () { showBlocks(timelineBlocks, offset); }, 100) |
||
12 | : window.requestAnimationFrame(function () { showBlocks(timelineBlocks, offset); }); |
||
13 | }); |
||
14 | |||
15 | function hideBlocks (blocks, offset) { |
||
16 | blocks.each(function () { |
||
17 | ($(this).offset().top > $(window).scrollTop() + $(window).height() * offset) && $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden'); |
||
18 | }); |
||
19 | } |
||
20 | |||
21 | function showBlocks (blocks, offset) { |
||
22 | blocks.each(function () { |
||
23 | ($(this).offset().top <= $(window).scrollTop() + $(window).height() * offset && $(this).find('.cd-timeline-img').hasClass('is-hidden')) && $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in'); |
||
24 | }); |
||
25 | } |
||
26 | }); |
||
27 |