-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-transition.js
45 lines (44 loc) · 1.2 KB
/
page-transition.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
let transitionTrigger = $(".transition-trigger");
let introDurationMS = 1300;
let exitDurationMS = 1200;
let excludedClass = "no-transition";
// On Page Load
if (transitionTrigger.length > 0) {
transitionTrigger.click();
$("body").addClass("no-scroll-transition");
setTimeout(() => {
$("body").removeClass("no-scroll-transition");
}, introDurationMS);
}
// On Link Click
$("a").on("click", function (e) {
if (
$(this).prop("hostname") == window.location.host &&
$(this).attr("href").indexOf("#") === -1 &&
!$(this).hasClass(excludedClass) &&
$(this).attr("target") !== "_blank" &&
transitionTrigger.length > 0
) {
e.preventDefault();
$("body").addClass("no-scroll-transition");
let transitionURL = $(this).attr("href");
transitionTrigger.click();
setTimeout(function () {
window.location = transitionURL;
}, exitDurationMS);
}
});
// On Back Button Tap
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload();
}
};
// Hide Transition on Window Width Resize
setTimeout(() => {
$(window).on("resize", function () {
setTimeout(() => {
$(".transition").css("display", "none");
}, 50);
});
}, introDurationMS);