(function($) { $(document).ready(function(){ $('.nav-btn').click(function(event) { event.preventDefault(); $('.main-header').toggleClass('collapsed').toggleClass('expanded'); }); // On before slide change $('.slider').on('beforeChange', function(event, slick, currentSlide, nextSlide){ // Trigger the scroll event $(window).scroll(); }); // On init $('.slider').on('init', function(event, slick){ // Trigger the scroll event $(window).scroll(); }); $('.slider').slick({ autoplay : true, autoplaySpeed : 5000, arrows : false, dots : true, }); }); if($('.blocks-gallery-item a').length) { $('.blocks-gallery-item a').next('figcaption').hide(); console.log('fancybox init'); $().fancybox({ selector : '.blocks-gallery-item a', //this allows for auto-grouping by selector instead of using data-fancybox="group-name" data tag loop: true, caption : function( instance, item ) { return $(this).next('figcaption').html(); //grab sibling figcaption } }); } /* Parallax Scrolling */ $.fn.moveIt = function(){ console.log('moveIt'); var $window = $(window); var instances = []; $(this).each(function(){ instances.push(new moveItItem($(this))); }); window.onscroll = function(){ var scrollTop = $window.scrollTop(); instances.forEach(function(inst){ inst.update(scrollTop); }); }; }; var moveItItem = function(el){ this.el = $(el); this.speed = parseInt(this.el.attr('data-scroll-speed')); }; moveItItem.prototype.update = function(scrollTop) { if(!isElementInViewport(this.el)){ return; } if ($(window).width() > 992 && $(window).height() > 600) { var pageY = this.el.offset(); var pos = (scrollTop - pageY.top) / this.speed; this.el.css('transform', 'translateY(' +pos + 'px)'); } }; function isElementInViewport (el, verticaloffset) { var win = $(window); var viewport = { top : win.scrollTop(), left : win.scrollLeft() }; viewport.right = viewport.left + win.width(); viewport.bottom = viewport.top + win.height(); var bounds = el.offset(); bounds.right = bounds.left + el.outerWidth(); bounds.bottom = bounds.top + el.outerHeight(); return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); } $(function(){ $('[data-scroll-speed]').moveIt(); }); })( jQuery );