-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.js
74 lines (58 loc) · 2.28 KB
/
file.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
//************Function that gets rid of preloader *//
window.addEventListener("load", ()=>{
const preloader = document.querySelector(".preloader");
const sectionviewer = document.querySelector("section");
preloader.classList.add("preloader-finish");
sectionviewer.classList.add("sectionclass");
})
// ************CODE FOR TOP ANIMATION BAR***********//
const progressBar = document.querySelector("#progressBar");
const section = document.querySelector("section");
const animateProgressBar = () => {
let scrollDistance = - section.getBoundingClientRect().top;
let progressWidth =
(scrollDistance
(section.getBoundingClientRect().height -
document.documentElement.clientHeight))
* 100;
//console.log(progressWidth)
let value = Math.floor(progressWidth);
progressBar.style.width = value + "%";
//console.log("scrollDistance "+ scrollDistance)
//console.log("progressWidth "+ progressWidth)
//console.log("documentElement "+ document.documentElement.clientHeight)
//console.log("Height "+ section.getBoundingClientRect().height)
}
window.addEventListener("scroll", animateProgressBar)
var btn = document.querySelector("#colorinput");
var box = document.querySelector(".box");
box.addEventListener("mouseover", function(){box.style.backgroundColor = "blue"})
box.addEventListener("mouseout", function(){
box.style.backgroundColor = "red"})
function colorChange(){
var colorInp = document.querySelector("#colorinput").value;
document.querySelector("body").style.backgroundColor = colorInp;
}
//*****************ANIMATE THE HEADING************/
const heading1 = document.querySelector(".heading1");
const heading1Txt = heading1.textContent;
const splitText= heading1Txt.split("");
heading1.textContent="";
for (let t = 0 ; t< splitText.length; t++){
heading1.innerHTML +="<span>" + splitText[t]+"</span>"
}
let char = 0;
let timer = setInterval(onTick,120);
function onTick(){
const span = heading1.querySelectorAll("span")[char];
span.classList.add("fade")
char++;
if (char === splitText.length){
complete();
return;
}
}
function complete(){
clearInterval(timer);
timer = null
}