-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
194 lines (159 loc) · 5.92 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
(function ($) {
"use strict";
// Preloader
$(window).on('load', function () {
if ($('#preloader').length) {
$('#preloader').delay(100).fadeOut('slow', function () {
$(this).remove();
});
}
});
// Back to top button
$(window).scroll(function() {
if ($(this).scrollTop() > 100) {
$('.back-to-top').fadeIn('slow');
} else {
$('.back-to-top').fadeOut('slow');
}
});
$('.back-to-top').click(function(){
$('html, body').animate({scrollTop : 0},1500, 'easeInOutExpo');
return false;
});
// Initiate the wowjs animation library
new WOW().init();
// Initiate superfish on nav menu
$('.nav-menu').superfish({
animation: {
opacity: 'show'
},
speed: 400
});
// Mobile Navigation
if ($('#nav-menu-container').length) {
var $mobile_nav = $('#nav-menu-container').clone().prop({
id: 'mobile-nav'
});
$mobile_nav.find('> ul').attr({
'class': '',
'id': ''
});
$('body').append($mobile_nav);
$('body').prepend('<button type="button" id="mobile-nav-toggle"><i class="fa fa-bars"></i></button>');
$('body').append('<div id="mobile-body-overly"></div>');
$('#mobile-nav').find('.menu-has-children').prepend('<i class="fa fa-chevron-down"></i>');
$(document).on('click', '.menu-has-children i', function(e) {
$(this).next().toggleClass('menu-item-active');
$(this).nextAll('ul').eq(0).slideToggle();
$(this).toggleClass("fa-chevron-up fa-chevron-down");
});
$(document).on('click', '#mobile-nav-toggle', function(e) {
$('body').toggleClass('mobile-nav-active');
$('#mobile-nav-toggle i').toggleClass('fa-times fa-bars');
$('#mobile-body-overly').toggle();
});
$(document).click(function(e) {
var container = $("#mobile-nav, #mobile-nav-toggle");
if (!container.is(e.target) && container.has(e.target).length === 0) {
if ($('body').hasClass('mobile-nav-active')) {
$('body').removeClass('mobile-nav-active');
$('#mobile-nav-toggle i').toggleClass('fa-times fa-bars');
$('#mobile-body-overly').fadeOut();
}
}
});
} else if ($("#mobile-nav, #mobile-nav-toggle").length) {
$("#mobile-nav, #mobile-nav-toggle").hide();
}
// Header scroll class
$(window).scroll(function() {
if ($(this).scrollTop() > 100) {
$('#header').addClass('header-scrolled');
} else {
$('#header').removeClass('header-scrolled');
}
});
if ($(window).scrollTop() > 100) {
$('#header').addClass('header-scrolled');
}
// Smooth scroll for the menu and links with .scrollto classes
$('.nav-menu a, #mobile-nav a, .scrollto').on('click', function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
if (target.length) {
var top_space = 0;
if ($('#header').length) {
top_space = $('#header').outerHeight();
if (! $('#header').hasClass('header-scrolled')) {
top_space = top_space - 20;
}
}
$('html, body').animate({
scrollTop: target.offset().top - top_space
}, 1500, 'easeInOutExpo');
if ($(this).parents('.nav-menu').length) {
$('.nav-menu .menu-active').removeClass('menu-active');
$(this).closest('li').addClass('menu-active');
}
if ($('body').hasClass('mobile-nav-active')) {
$('body').removeClass('mobile-nav-active');
$('#mobile-nav-toggle i').toggleClass('fa-times fa-bars');
$('#mobile-body-overly').fadeOut();
}
return false;
}
}
});
// Navigation active state on scroll
var nav_sections = $('section');
var main_nav = $('.nav-menu, #mobile-nav');
var main_nav_height = $('#header').outerHeight();
$(window).on('scroll', function () {
var cur_pos = $(this).scrollTop();
nav_sections.each(function() {
var top = $(this).offset().top - main_nav_height,
bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
main_nav.find('li').removeClass('menu-active menu-item-active');
main_nav.find('a[href="#'+$(this).attr('id')+'"]').parent('li').addClass('menu-active menu-item-active');
}
});
});
// Intro carousel
var introCarousel = $(".carousel");
var introCarouselIndicators = $(".carousel-indicators");
introCarousel.find(".carousel-inner").children(".carousel-item").each(function(index) {
(index === 0) ?
introCarouselIndicators.append("<li data-target='#introCarousel' data-slide-to='" + index + "' class='active'></li>") :
introCarouselIndicators.append("<li data-target='#introCarousel' data-slide-to='" + index + "'></li>");
$(this).css("background-image", "url('" + $(this).children('.carousel-background').children('img').attr('src') +"')");
$(this).children('.carousel-background').remove();
});
$(".carousel").swipe({
swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
if (direction == 'left') $(this).carousel('next');
if (direction == 'right') $(this).carousel('prev');
},
allowPageScroll:"vertical"
});
// jQuery counterUp (used in Facts section)
$('[data-toggle="counter-up"]').counterUp({
delay: 10,
time: 1000
});
// Clients carousel (uses the Owl Carousel library)
$(".clients-carousel").owlCarousel({
autoplay: true,
dots: true,
loop: true,
responsive: { 0: { items: 2 }, 768: { items: 4 }, 900: { items: 6 }
}
});
// Testimonials carousel (uses the Owl Carousel library)
$(".testimonials-carousel").owlCarousel({
autoplay: true,
dots: true,
loop: true,
items: 1
});
})(jQuery);