This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
71 lines (58 loc) · 1.63 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
$( document ).ready( function () {
var hamburger = $( '#hamburger' );
// DRAWER:
var drawer = $( '#drawer' );
var overlay = $( '#drawer-overlay' );
var close = $( '#close' );
// MODAL:
var modal = $( '#modal' );
var closeModal = $( '#close-modal' );
// EVENTLISTENER:
hamburger.on( 'click', function () {
toggle( 'show-drawer' );
} );
close.on( 'click', function () {
toggle( 'hide-drawer' );
} );
overlay.on( 'click', function () {
toggle( 'hide-drawer' );
} );
closeModal.on( 'click', function () {
toggle( 'hide-modal' );
} );
// FUNCTIONS DECLARATION:
setTimeout( function () {
toggle( 'show-modal' );
}, 1000 );
function toggleOverlay( state ) {
if ( state == true ) {
overlay.on( 'click', function () {
toggle( 'hide-drawer' );
} );
} else {
overlay.off( 'click' );
}
}
function toggle( action ) {
switch ( action ) {
case 'show-drawer':
overlay.removeClass( 'hidden' );
drawer.addClass( 'active' );
break;
case 'hide-drawer':
drawer.removeClass( 'active' );
overlay.addClass( 'hidden' );
break;
case 'show-modal':
toggleOverlay( false );
overlay.removeClass( 'hidden' );
modal.removeClass( 'hidden' );
break;
case 'hide-modal':
overlay.addClass( 'hidden' );
modal.addClass( 'hidden' );
toggleOverlay( true );
break;
}
}
} );