-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
|
||
.btn-right { | ||
position: absolute; | ||
top: 48%; | ||
right: 31%; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const images = [ | ||
"./img/photo1.jpg", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); |
There was a problem hiding this comment.
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