Skip to content

Instantly share code, notes, and snippets.

@PatrickCLipscomb
Created November 14, 2017 18:49
Show Gist options
  • Save PatrickCLipscomb/290d3919dd546365707129c2fb217845 to your computer and use it in GitHub Desktop.
Save PatrickCLipscomb/290d3919dd546365707129c2fb217845 to your computer and use it in GitHub Desktop.
// these animation scripts run on irvingpethospital.com
jQuery(document).ready(function() {
try {
logoAndBannerSlideIn();
dogAndCatSlideUpOnScroll();
servicePageTitleBackground();
dogOrCatAboveServicePageHeader();
alternateMenuItems();
} catch (e) {
console.log(e);
}
});
function alternateMenuItems() {
var $ = jQuery;
var menuItems = $('#menu-left_menu > li');
var dog = '<img src="/wp-content/uploads/2017/06/dog-1.png"></img>';
var cat = '<img src="/wp-content/uploads/2017/07/cat-3.png"></img>';
menuItems.each(function(index) {
index % 2 === 0 ? addPetToSecondaryMenus(dog, 'dog', $(this)) : addPetToSecondaryMenus(cat, 'cat', $(this));
});
}
function addPetToSecondaryMenus(image, animal, menuItem) {
var $ = jQuery;
if (menuItem.find('div.second').length) {
menuItem.find('div.second').prepend(image);
var img = menuItem.find('img');
if (animal === 'dog') {
img.addClass('dog-on-menu');
menuItem.find('ul').hover(function() {
img.attr('src', '/wp-content/uploads/2017/06/dog-2.png');
}, function() {
img.attr('src', '/wp-content/uploads/2017/06/dog-1.png');
});
} else {
img.addClass('cat-on-menu');
menuItem.find('ul').hover(function() {
img.attr('src', '/wp-content/uploads/2017/07/cat-2.png');
}, function() {
img.attr('src', '/wp-content/uploads/2017/07/cat-3.png');
});
}
} else {
menuItem.append(image);
var img = menuItem.find('img');
animal === 'dog' ? img.addClass('dog-in-menu') : img.addClass('cat-in-menu');
menuItem.hover(function() {
img.show();
}, function() {
img.hide();
});
}
}
function getServiceItemOddOrEven() {
var $ = jQuery;
var services = [];
var subServices = [];
var order;
var result;
$('.main_menu > ul > li > a .item_inner').each(function() {
services.push($(this));
});
for (var i = 0; i < services.length; i++) {
if (services[i].text() === "Services") {
services[i].parents('.menu-item').find('.second .item_inner').each(function() {
subServices.push($(this));
});
}
}
var currentService = $('.title_subtitle_holder span').text();
for (var i = 0; i < subServices.length; i++) {
if (subServices[i].text() === currentService) {
order = i + 1;
}
}
order % 2 === 0 ? result = 'even' : result = 'odd';
return result;
}
function dogOrCatAboveServicePageHeader() {
var $ = jQuery;
if ($('.parent-pageid-1764').length) {
var oddOrEven = getServiceItemOddOrEven();
oddOrEven === 'odd' ? servicePageHeaderAnimal('dog') : servicePageHeaderAnimal('cat');
}
}
function servicePageHeaderAnimal(arg) {
var $ = jQuery;
arg === 'dog' ? $('.title_subtitle_holder').prepend('<img src="/wp-content/uploads/2017/06/dog-1.png" class="service-page-dog-header"></img>') : $('.title_subtitle_holder').prepend('<img src="/wp-content/uploads/2017/07/cat-3.png" class="service-page-cat-header"></img>');
var image = $('.title_subtitle_holder img');
var flag = true
$(document).on('mousemove', function() {
if (event.pageY > 335 && flag) {
flag = false;
arg === 'dog' ? image.attr('src', '/wp-content/uploads/2017/06/dog-2.png') : image.attr('src', '/wp-content/uploads/2017/07/cat-2.png');
} else if (event.pageY < 335 && !flag) {
flag = true;
arg === 'dog' ? image.attr('src', '/wp-content/uploads/2017/06/dog-1.png') : image.attr('src', '/wp-content/uploads/2017/07/cat-3.png');
}
})
}
function servicePageHeaderCat() {
var $ = jQuery;
$('.title_subtitle_holder').prepend('<img src="/wp-content/uploads/2017/07/cat-3.png" class="service-page-cat-header"></img>');
}
function logoAndBannerSlideIn() {
var $ = jQuery;
setTimeout(function() {
$('.logo_wrapper').addClass('logoSlideFromTop');
$('.header-banner').addClass('slideInRight');
$('.header-banner').slideDown(1000);
}, 500);
}
function servicePageTitleBackground() {
var $ = jQuery;
if ($('.parent-pageid-1764').length) {
setTimeout(function() {
$('.parent-pageid-1764 .title_holder').addClass('servicepage-title-background');
$('.parent-pageid-1764 .title_subtitle_holder').css('opacity', '1');
}, 1800);
}
}
function dogAndCatSlideUpOnScroll() {
var $ = jQuery;
$('#homepage-intro-area').prepend('<img src="/wp-content/uploads/2017/06/dog-2.png" class="slidingDog"></img>');
$('#homepage-intro-area').prepend('<img src="/wp-content/uploads/2017/07/cat-2.png" class="slidingCat"></img>');
$(document).scroll(function() {
console.log($(window).scrollTop() - $(window).height())
if (($(window).scrollTop() - $(window).height()) > -800) {
$('#homepage-intro-area').addClass('homeAreaBorderTop');
$('.slidingDog').addClass('dogSlideUp');
$('.slidingCat').addClass('catSlideUp');
setTimeout(function() {
$('.slidingDog').addClass('showPaws');
$('.slidingCat').addClass('showPaws');
}, 1500)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment