-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
115 lines (93 loc) · 3.19 KB
/
script.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
$(document).ready(function() {
// Variáveis
var height = window.innerHeight,
x = 0, y = height / 2,
curveX = 0,
curveY = 0,
targetX = 0,
xitteration = 0,
yitteration = 0,
menuExpanded = false;
// DOM element references
var blob = $('#blob'),
blobPath = $('#blob-path'),
hamburger = $('.hamburger');
// Event handler for mouse movement
$(this).on('mousemove', function(e) {
x = e.pageX;
y = e.pageY;
});
// Event handlers for menu interaction
$('.hamburger, .menu-inner').on('mouseenter', function() {
$(this).parent().addClass('expanded');
menuExpanded = true;
});
$('.menu-inner').on('mouseleave', function() {
menuExpanded = false;
$(this).parent().removeClass('expanded');
});
// Easing function for smooth animation
function easeOutExpo(currentIteration, startValue, changeInValue, totalIterations) {
return changeInValue * (-Math.pow(2, -10 * currentIteration / totalIterations) + 1) + startValue;
}
// Constants for animation
var hoverZone = 150;
var expandAmount = 50;
// Function to create SVG curve animation
function svgCurve() {
if ((curveX > x - 1) && (curveX < x + 1)) {
xitteration = 0;
} else {
if (menuExpanded) {
targetX = 0;
} else {
xitteration = 0;
if (x > hoverZone) {
targetX = 0;
} else {
targetX = -(((60 + expandAmount) / 100) * (x - hoverZone));
}
}
xitteration++;
}
if ((curveY > y - 1) && (curveY < y + 1)) {
yitteration = 0;
} else {
yitteration = 0;
yitteration++;
}
// Calculate curve values
curveX = easeOutExpo(xitteration, curveX, targetX - curveX, 60);
curveY = easeOutExpo(yitteration, curveY, y - curveY, 60);
var anchorDistance = 250;
var curviness = anchorDistance - 60;
// SVG path definition
var newCurve2 = "M60," + height + "H0V0h60v" + (curveY - anchorDistance) + "c0," + curviness + "," + curveX + "," + curviness + "," + curveX + "," + anchorDistance + "S60," + (curveY) + ",60," + (curveY + (anchorDistance * 2)) + "V" + height + "z";
// Apply changes to DOM elements
blobPath.attr('d', newCurve2);
blob.width(curveX + 60);
hamburger.css('transform', 'translate(' + curveX + 'px, ' + curveY + 'px)');
$('h2').css('transform', 'translateY(' + curveY + 'px)');
// Animação contínua
window.requestAnimationFrame(svgCurve);
}
// Chamada animação
window.requestAnimationFrame(svgCurve);
// Função para fechar o modal
function closeModal() {
$('.modal').removeClass('open');
}
// Fechar o modal quando o botão dentro do modal é clicado
$('.close-button').on('click', function () {
closeModal();
});
// Evento de clique nos links do menu para abrir os modais
$('.open-modal').on('click', function (e) {
e.preventDefault();
var modalId = $(this).data('modal-id');
// Fechar o modal atual antes de abrir o novo
closeModal();
// Abrir o novo modal
$('#' + modalId).addClass('open');
});
});