jQuery(function ($) { //#main-slider $(function () { $('#main-slider.carousel').carousel({ interval: 8000, cycle: true }); }); $('.centered').each(function (e) { $(this).css('margin-top', ($('#main-slider').height() - $(this).height()) / 2); }); $(window).resize(function () { $('.centered').each(function (e) { $(this).css('margin-top', ($('#main-slider').height() - $(this).height()) / 2); }); }); //contact form var form = $('.contact-form'); form.submit(function () { $this = $(this); $.post($(this).attr('action'), $this.serialize(), function (data) { $this.prev().text(data.message).fadeIn().delay(3000).fadeOut(); }, 'json'); return false; }); //goto top $('.gototop').click(function (event) { event.preventDefault(); $('html, body').animate({ scrollTop: $("body").offset().top }, 500); }); //Pretty Photo $("a[rel^='prettyPhoto']").prettyPhoto({ social_tools: false }); }); const items = document.querySelectorAll("#timeline li"); const isInViewport = (el) => { const rect = el.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWhith || document.documentElement.clientWidth) ); }; const run = () => items.forEach((item) => { if (isInViewport(item)) { item.classList.add("show"); } }); // Events window.addEventListener("load", run); window.addEventListener("resize", run); window.addEventListener("scroll", run);