-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTASK1.js
80 lines (67 loc) · 2.54 KB
/
TASK1.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
//JS for Contact Section
function fn1()
{
var a=document.getElementById("name").value;
var b=document.getElementById("phone").value;
var c=document.getElementById("text").value;
var d=document.getElementById("email").value;
var emailpattern=/^[^]*@[^]*\.[a-z]{2,3}$/;
if(!(a)){alert("Enter Name");}
if(!(isNaN(b))&&!(b.length==10)){alert("Enter valid phone number");}
if(!(d.match(emailpattern))){alert("Enter valid email id");}
else if(a&&b&&d){
let e=confirm("Are you sure you want to submit?");
if(e){
alert("Your Response has been submitted.Thank you.");}
else{
alert("Oops Your Response has not submitted.Fill it Again");}}
}
//JS for nav section
let nav = document.querySelector("nav");
let scrollBtn = document.querySelector(".scroll-btn a");
console.log(scrollBtn);
let val;
window.onscroll = function() {
if(document.documentElement.scrollTop > 20){
nav.classList.add("sticky");
scrollBtn.style.display = "block";
}else{
nav.classList.remove("sticky");
scrollBtn.style.display = "none";
}
}
// Navigation JS Code
let body = document.querySelector("body");
let navBar = document.querySelector(".navbar");
let menuBtn = document.querySelector(".menu-btn");
let cancelBtn = document.querySelector(".cancel-btn");
menuBtn.onclick = function(){
navBar.classList.add("active");
menuBtn.style.opacity = "0";
menuBtn.style.pointerEvents = "none";
body.style.overflow = "hidden";
scrollBtn.style.pointerEvents = "none";
}
cancelBtn.onclick = function(){
navBar.classList.remove("active");
menuBtn.style.opacity = "1";
menuBtn.style.pointerEvents = "auto";
body.style.overflow = "auto";
scrollBtn.style.pointerEvents = "auto";
}
// Side Navigation Bar
let navLinks = document.querySelectorAll(".menu li a");
for (var i = 0; i < navLinks.length; i++) {
navLinks[i].addEventListener("click" , function() {
navBar.classList.remove("active");
menuBtn.style.opacity = "1";
menuBtn.style.pointerEvents = "auto";
});
}
//JS for dynamic images
let image=document.getElementById('image');
let images=['https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQgdd5of8Y9HOcmUyi6d0hD4X-rViaAnnCPmw&usqp=CAU','https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQuAo-hDPXwazzBbggUnseKSMYnYH6G6Z_x7A&usqp=CAU','https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2fTEVrIwfcvJ81nAeBdZG09RnBYAviOIdlg&usqp=CAU']
setInterval(function(){
let r=Math.floor(Math.random()*3);
image.src=images[r];
},800);