-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d914b6
commit d2db3b2
Showing
14 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Draggable Carousel</title> | ||
</head> | ||
<body> | ||
|
||
<div id="image-track" data-mouse-down-at="0" data-prev-percentage="0"> | ||
<img class="image" src="images/1.jpg" draggable="false" /> | ||
<img class="image" src="images/2.jpg" draggable="false" /> | ||
<img class="image" src="images/3.jpg" draggable="false" /> | ||
<img class="image" src="images/4.jpg" draggable="false" /> | ||
<img class="image" src="images/5.jpg" draggable="false" /> | ||
<img class="image" src="images/6.jpg" draggable="false" /> | ||
<img class="image" src="images/7.jpg" draggable="false" /> | ||
<img class="image" src="images/8.jpg" draggable="false" /> | ||
<img class="image" src="images/9.jpg" draggable="false" /> | ||
<img class="image" src="images/10.jpg" draggable="false" /> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const track = document.getElementById("image-track"); | ||
|
||
window.onmousedown = (e) => { | ||
track.dataset.mouseDownAt = e.clientX; | ||
}; | ||
window.onmouseup = () => { | ||
track.dataset.mouseDownAt = "0"; | ||
track.dataset.prevPercentage = track.dataset.percentage; | ||
} | ||
|
||
window.onmousemove = e => { | ||
if (track.dataset.mouseDownAt === "0") return; | ||
|
||
const mouseDelta = parseFloat(track.dataset.mouseDownAt) - e.clientX, | ||
maxDelta = window.innerWidth / 2; | ||
|
||
const percentage = (mouseDelta / maxDelta) * -100, | ||
nextPercentageUnconstrained = parseFloat(track.dataset.prevPercentage) + percentage, | ||
nextPercentage = Math.max(Math.min(nextPercentageUnconstrained, 0), -100); | ||
|
||
track.dataset.percentage = nextPercentage; | ||
|
||
track.animate({ | ||
transform: `translate(${nextPercentage}%, -50%)` | ||
}, { | ||
duration: 1200, | ||
fill: "forwards" | ||
}); | ||
|
||
for (const image of track.getElementsByClassName("image")) { | ||
image.animate({ | ||
objectPosition: `${100 + nextPercentage}% center` | ||
}, { | ||
duration: 1200, | ||
fill: "forwards" | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
body { | ||
height: 100vh; | ||
width: 100vw; | ||
background-color: #10041a; | ||
margin: 0rem; | ||
overflow: hidden; | ||
} | ||
|
||
#image-track { | ||
display: flex; | ||
gap: 4vmin; | ||
position: absolute; | ||
left: 50%; | ||
top: 50%; | ||
transform: translate(0%, -50%); | ||
user-select: none; | ||
/* -- Prevent image highlighting -- */ | ||
} | ||
|
||
#image-track>.image { | ||
width: 40vmin; | ||
height: 56vmin; | ||
object-fit: cover; | ||
object-position: 100% center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters