Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made a carousel #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added img/photo1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/photo3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/photo4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/photo5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/photo6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.arcticmonkeys {
position: relative;
width: 503px;
margin: auto;
padding: 40px;
display: none;
}

.btn-left {
position: absolute;
top: 48%;
left: 34%;
transform: translate(-53%, -53%);
background-image: url(./svg/left.png);
background-repeat: no-repeat;
width: 40px;
height: 40px;
border-radius: 20%;
outline: none;
border: none;
background-color: black;
}

.btn-left:hover {
background-color: white;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, we don’t use colors like this
only hex

And you should add variables

}

.btn-right {
position: absolute;
top: 48%;
right: 31%;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost All styles are copy paste

transform: translate(-53%, -53%);
background-image: url(./svg/right.png);
background-repeat: no-repeat;
width: 40px;
height: 40px;
border-radius: 20%;
outline: none;
border: none;
background-color: black;
}

.btn-right:hover {
background-color: white;
}

.point {
top: 50%;
left: 50%;
border-radius: 50%;
width: 15px;
height: 15px;
background-color: BlanchedAlmond;
display: inline-block;
text-align: center;
}

#main {
text-align: center;
}
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./index.css">
<title>Carousel</title>
</head>
<body>
<div id="imgContainer"></div>

<input id="clickL" type="button" value=" " class="btn-left">
<input id="clickR" type="button" value=" " class="btn-right">

<div id="main">
<div class="point"></div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to create it dynamically

<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
</div>

<script src="./index.js"></script>
</body>
</html>
86 changes: 86 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const images = [
"./img/photo1.jpg",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a dynamic array and use indexes

What if you have 100000 images?

"./img/photo2.jpg",
"./img/photo3.jpg",
"./img/photo4.jpg",
"./img/photo5.jpg",
"./img/photo6.jpg",
];

const container = document.getElementById("imgContainer");

function createImages() {
for (let i = 0; i < images.length; i++) {
const img = document.createElement("img");
img.className = "arcticmonkeys";

img.src = images[i];
container.appendChild(img);
}
}
createImages();

const elems = document.getElementsByClassName("arcticmonkeys");

const point = document.getElementsByClassName("point");

elems[0].style.display = "block";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u do it while creative the element?


point[0].style.background = "Burlywood";

function createButtons() {
const clickL = document.getElementById("clickL");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean clickL?

const clickR = document.getElementById("clickR");

let index = 0;

function addChangeNone() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddChangeNone? Rename

elems[index].style.display = "none";
point[index].style.background = "BlanchedAlmond";
}

function addChangeBlock() {
elems[index].style.display = "block";
point[index].style.background = "Burlywood";
}

clickL.addEventListener(
"click",
(clickLeft = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it’�?

if (!index) {
addChangeNone();

index = elems.length - 1;

addChangeBlock();
} else {
addChangeNone();

index--;

addChangeBlock();
}
})
);

clickR.addEventListener(
"click",
(clickRight = () => {
if (index >= elems.length - 1) {
addChangeNone();

index = 0;

addChangeBlock();
} else {
addChangeNone();

index++;

addChangeBlock();
}
})
);
}

createButtons();
Binary file added svg/Ellipse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svg/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svg/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.