-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
124 lines (113 loc) · 3.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// smooth scroll to anchors
function smoothScroll() {
$("a").on('click', function(event) {
if (this.hash !== '') {
event.preventDefault();
let hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 900, function(){
window.location.hash = hash;
});
}
});
}
// expand and collapse pet descriptions
function expandDescription() {
$('.results').on('click', '.clickToExpand', function (event) {
$(this).siblings('p').slideToggle();
$(this).toggleClass('active');
$('.pet').css('display:block');
});
}
// background slide show
function slideShow() {
let activeDiv = 1;
showDiv(activeDiv);
let timer = setInterval(changeDiv, 5000);
function changeDiv() {
activeDiv++;
if (activeDiv == 6) {
activeDiv = 1;
}
showDiv(activeDiv);
}
function showDiv(num) {
$('.slide').fadeOut(3000);
$('.slide' + num).fadeIn(1000);
}
}
function slideOutHeroSection() {
$('.heroButton').on('click', function() {
$('.herosection').slideUp('slow');
$('header').slideUp('slow');
$('main').slideUp('slow');
$('.slideShow').slideUp('slow', function() {
$('.slideShow').addClass('fullheight');
});
$('.animalForm').prop('hidden', false).slideUp('slow', function() {
$(this).removeClass('hidden');
});
});
}
// show more filtering options on form
function moreFilterOptions() {
$('.filters').on('click', function(event) {
event.preventDefault();
$(this).toggleClass('showFilters');
// $('.sizeAgeSex').toggleClass('hidden');
$('.sizeAgeSex').parent().slideToggle();
// $('.sizeAgeSex').toggleClass('flexDisplay');
})
}
// fade in and out scroll to top button and go to vet results button
function fadeinOnScroll() {
$(window).scroll(function() {
if($(this).scrollTop() > 2000) {
$('.scrollbackdiv').fadeIn();
$('.gotovetresultsdiv').fadeIn();
} else {
$('.scrollbackdiv').fadeOut();
$('.gotovetresultsdiv').fadeOut();
}
});
}
// light box function
function lightboxRun() {
$('.results').on('click', '.petnameandphoto .petlink', function (event) {
event.preventDefault();
console.log('hi');
let petimage = $(event.currentTarget).attr('href');
let altTag = $(event.currentTarget).attr('title');
const item = `<div class="lightbox"><button class="close"><i class="fa fa-times-circle" aria-hidden="true"></i></button><img src="${petimage}" alt="${altTag}"/></div>`;
$('.lightboxcontainer').hide().prop('hidden', false).html(item).fadeIn();
closeLightBox();
});
}
// close lightbox function
function closeLightBox () {
$('.lightbox').on('click', '.close', function (event) {
$('.lightbox').fadeOut();
});
$('.lightbox').on('click', function (event) {
$('.lightbox').fadeOut();
});
}
function revealSearchButton() {
$('form').on('click', function() {
let textInput = $('.myLocation').val();
if($('.animalType > input').is(':checked')) {
$('.formbuttons').slideDown(function() {$('.formbuttons').removeClass('hidden')}
);
}
});
}
// run all of the functions
$(revealSearchButton);
$(slideOutHeroSection);
$(lightboxRun);
$(fadeinOnScroll);
$(moreFilterOptions);
$(slideShow);
$(expandDescription);
$(smoothScroll);