Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a33595e

Browse files
committed
interactive gallery + interactive form(without sending to server)
1 parent 82e4f39 commit a33595e

File tree

3 files changed

+383
-7
lines changed

3 files changed

+383
-7
lines changed

index.html

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,38 @@
1818
<section class="home" id="home">
1919
<div class="home-darkness">
2020
<nav class="home-darkness__navbar">
21-
<a href="#about">about</a>
22-
<a href="#projects">projects</a>
23-
<a href="#footer">contacts</a>
21+
<a class="home-darkness__navbar_link" href="#about">about</a>
22+
<a class="home-darkness__navbar_link" href="#photos">photos</a>
23+
<a class="home-darkness__navbar_link" href="#projects">projects</a>
24+
<a class="home-darkness__navbar_link" href="#footer">contacts</a>
25+
<span id="show-form" class="home-darkness__navbar_link home-darkness__navbar_write-me">write me!</span>
2426
</nav>
2527

28+
<div class="popup">
29+
<div class="popup__close">&times;</div>
30+
<form action="#" class="form" id="write-me" method="POST" novalidate>
31+
<h2>Write Me</h2>
32+
<div class="form-element">
33+
<label class="form-element__label" for="name">Name</label>
34+
<input class="form__input" type="text" id="name" placeholder="Enter name">
35+
<label class="error-label_invisible"></label>
36+
</div>
37+
<div class="form-element">
38+
<label class="form-element__label" for="email">Email</label>
39+
<input data-email="true" class="form__input" type="text" id="email" placeholder="Enter email">
40+
<label class="error-label_invisible"></label>
41+
</div>
42+
<div class="form-element">
43+
<label class="form-element__label" for="textarea"></label>
44+
<textarea id="textarea" class="form__input" rows="5" cols="30" placeholder="Comment here"></textarea>
45+
<label class="error-label_invisible"></label>
46+
</div>
47+
<div class="form-element">
48+
<button type="submit" class="form__submit">Send</button>
49+
</div>
50+
</form>
51+
</div>
52+
2653
<div class="home__main">
2754
<h3>Welcome</h3>
2855
<h1>I am Maria Malykh</h1>
@@ -76,6 +103,34 @@ <h3>education</h3>
76103
</div>
77104
</section>
78105

106+
<section class="gallery" id="photos">
107+
<div class="title">
108+
<h2>My photos</h2>
109+
</div>
110+
111+
<div class="gallery__full-image" id="fullImgBox">
112+
<img src="./images/iss.jpg" alt="opened image" class="photo-grid__item" id="fullImg">
113+
<span class="close" onclick="closeFullImg()">&times;</span>
114+
<span class="arrow arrow_right" onclick="changeSlides(1)">&#10095;</span>
115+
<span class="arrow arrow_left" onclick="changeSlides(-1)">&#10094;</span>
116+
</div>
117+
118+
<div class="photo-grid">
119+
<img src="./images/cubesat_img.jpg" id="1" alt="окно поезда" class="photo-grid__item" onclick="showSlide(1)">
120+
<img src="./images/iss.jpg" id="2" alt="верхушки гор" class="photo-grid__item" onclick="showSlide(2)">
121+
<img src="./images/cubesat_img.jpg" id="3" alt="собака на сене" class="photo-grid__item" onclick="showSlide(3)">
122+
<img src="./images/iss.jpg" id="4" alt="холмы в тумане" class="photo-grid__item" onclick="showSlide(4)">
123+
<img src="./images/cubesat_img.jpg" id="5" alt="колесо на льду" class="photo-grid__item" onclick="showSlide(5)">
124+
<img src="./images/iss.jpg" id="6" alt="горы вдалеке" class="photo-grid__item" onclick="showSlide(6)">
125+
<img src="./images/cubesat_img.jpg" id="7" alt="горы" class="photo-grid__item" onclick="showSlide(7)">
126+
<img src="./images/iss.jpg" id="8" alt="знак пешеходного перехода" class="photo-grid__item" onclick="showSlide(8)">
127+
<img src="./images/cubesat_img.jpg" id="9" alt="горы в тумане" class="photo-grid__item" onclick="showSlide(9)">
128+
<img src="./images/iss.jpg" id="10" alt="одна гора вдалеке" class="photo-grid__item" onclick="showSlide(10)">
129+
<img src="./images/cubesat_img.jpg" id="11" alt="скалистый берег" class="photo-grid__item" onclick="showSlide(11)">
130+
<img src="./images/iss.jpg" id="12" alt="верхушки холмов в тумане" class="photo-grid__item" onclick="showSlide(12)">
131+
</div>
132+
</section>
133+
79134
<section class="projects" id="projects">
80135
<div class="title">
81136
<h2>My Projects</h2>
@@ -106,5 +161,6 @@ <h2>My Projects</h2>
106161
</footer>
107162

108163
</div>
164+
<script src="script.js"></script>
109165
</body>
110166
</html>

script.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const fullImgBox = document.getElementById("fullImgBox");
2+
const fullImg = document.getElementById("fullImg");
3+
const form = document.getElementById('write-me');
4+
let slideIndex = 1;
5+
6+
function validation() {
7+
function removeError(input) {
8+
const parent = input.parentNode;
9+
const errorLabel = parent.querySelector('.error-label_invisible');
10+
if (errorLabel.classList.contains('error-label')) {
11+
input.classList.remove('error');
12+
errorLabel.classList.remove('error-label')
13+
}
14+
}
15+
16+
function createError(input, text) {
17+
const parent = input.parentNode;
18+
input.classList.add('error');
19+
const errorLabel = parent.querySelector('.error-label_invisible');
20+
errorLabel.classList.add('error-label');
21+
errorLabel.textContent = text;
22+
}
23+
24+
const validateEmail = (email) => {
25+
return email.match(
26+
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
27+
);
28+
};
29+
30+
let result = true;
31+
const allInput = document.querySelectorAll('.form__input');
32+
33+
for (const input of allInput) {
34+
removeError(input);
35+
if (input.value === "") {
36+
result = false;
37+
createError(input, 'Field is empty');
38+
}
39+
40+
if (input.dataset.email) {
41+
removeError(input);
42+
if (!validateEmail(input.value)) {
43+
result = false;
44+
createError(input, 'Email is invalid');
45+
}
46+
}
47+
}
48+
49+
return result;
50+
}
51+
52+
form.addEventListener('submit', (event) => {
53+
event.preventDefault();
54+
55+
if (validation()) {
56+
57+
form.reset();
58+
}
59+
});
60+
61+
function openForm() {
62+
document.querySelector('.popup').classList.add('popup_active');
63+
}
64+
65+
function closeForm() {
66+
document.querySelector('.popup').classList.remove('popup_active');
67+
}
68+
69+
document.querySelector('#show-form').addEventListener('click', openForm);
70+
71+
document.querySelector('.popup__close').addEventListener('click', closeForm);
72+
73+
function openFullImg(picture) {
74+
fullImgBox.style.display = 'flex';
75+
fullImg.src = picture;
76+
}
77+
78+
function closeFullImg() {
79+
fullImgBox.style.display = 'none';
80+
}
81+
82+
function showSlides(n) {
83+
const slides = Array.from(document.querySelectorAll('.photo-grid__item'));
84+
const left_button = document.querySelector('.arrow_left');
85+
const right_button = document.querySelector('.arrow_right');
86+
closeFullImg();
87+
88+
openFullImg(slides[n].src);
89+
if (n === 1) {
90+
left_button.classList.add('arrow_inactive');
91+
} else {
92+
left_button.classList.remove('arrow_inactive');
93+
}
94+
95+
if (n === slides.length - 1) {
96+
right_button.classList.add('arrow_inactive');
97+
} else {
98+
right_button.classList.remove('arrow_inactive');
99+
}
100+
console.log(n);
101+
console.log(slides.length);
102+
}
103+
104+
function changeSlides(n) {
105+
if ((document.querySelector('.arrow_left').classList.contains('arrow_inactive') && n < 0) ||
106+
(document.querySelector('.arrow_right').classList.contains('arrow_inactive') && n > 0)) {
107+
return;
108+
}
109+
showSlides(slideIndex += n);
110+
}
111+
112+
function showSlide(n) {
113+
slideIndex = n;
114+
showSlides(n);
115+
}
116+
117+
document.addEventListener('keydown', (evt) => {
118+
if (evt.key === 'Escape') {
119+
closeFullImg();
120+
closeForm();
121+
}
122+
})

0 commit comments

Comments
 (0)