-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.js
51 lines (47 loc) · 1.42 KB
/
contact.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
var form = $('#contact'),
submit = form.find('[name="submit"]');
form.on('submit', function(e) {
e.preventDefault();
// avoid spamming buttons
if (submit.attr('value') !== 'Send')
return;
var valid = true;
form.find('input, textarea').removeClass('invalid').each(function() {
if (!this.value) {
$(this).addClass('invalid');
valid = false;
}
});
if (!valid) {
form.animate({left: '-3em'}, 50)
.animate({left: '3em'}, 100)
.animate({left: '0'}, 50);
} else {
submit.attr('value', 'Sending...')
.css({boxShadow: '0 0 200em 200em rgba(225, 225, 225, 0.6)',
backgroundColor: '#ccc'});
// simulate AJAX response
setTimeout(function() {
// step 1: slide labels and inputs
// when AJAX responds with success
// no animation for AJAX failure yet
form.find('label')
.animate({left: '100%'}, 500)
.animate({opacity: '0'}, 500);
}, 1000);
setTimeout(function() {
// step 2: show thank you message after step 1
submit.attr('value', 'Thank you :)')
.css({boxShadow: 'none'});
}, 2000);
setTimeout(function() {
// step 3: reset
form.find('input, textarea').val('');
form.find('label')
.css({left: '0'})
.animate({opacity: '1'}, 500);
submit.attr('value', 'Send')
.css({backgroundColor: ''});
}, 4000);
}
});