-
Notifications
You must be signed in to change notification settings - Fork 133
/
ScrollToTop.js
42 lines (35 loc) · 1.09 KB
/
ScrollToTop.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
const goTopBtn=document.querySelector('.go-top-btn')
window.addEventListener('scroll',checkHeight)
function checkHeight(){
if(window.scrollY>500){
goTopBtn.style.display="flex"
}
else{
goTopBtn.style.display="none"
}
}
goTopBtn.addEventListener('click', ()=>{
window.scrollTo({
top:0,
behavior:"smooth"
})
})
//contact form to excel sheet
const scriptURL = 'https://script.google.com/macros/s/AKfycbzUSaaX3XmlE5m9YLOHOBrRuCh2Ohv49N9bs4bew7xPd1qlgpvXtnudDs5Xhp3jF-Fx/exec';
const form = document.forms['submitToGoogleSheet']
const msg = document.getElementById("msg")
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form) })
.then(response => {
msg.innerHTML = "Message sent successfully"
setTimeout(function () {
msg.innerHTML = ""
}, 5000)
form.reset()
})
.catch(error => console.error('Error!', error.message))
})
function updateActiveSection() {
var scrollPosition = $(window).scrollTop();
}