Add mouse navigation
This commit is contained in:
parent
a3e81068c1
commit
b87bcdbb53
@ -7,11 +7,36 @@
|
|||||||
<style>
|
<style>
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
html, body { height: 100%; overflow: hidden; background: #1a1a1a; }
|
html, body { height: 100%; overflow: hidden; background: #1a1a1a; }
|
||||||
img { display: block; max-width: 100%; max-height: 100%; margin: auto; cursor: pointer; }
|
#container {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
img { max-width: 100%; max-height: 100%; cursor: pointer; }
|
||||||
|
.chevron {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
font-size: 48px;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 20px;
|
||||||
|
user-select: none;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
.chevron:hover { color: rgba(255, 255, 255, 0.9); }
|
||||||
|
.chevron.left { left: 10px; }
|
||||||
|
.chevron.right { right: 10px; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img id="random-img" alt="Random image">
|
<div id="container">
|
||||||
|
<img id="random-img" alt="Random image">
|
||||||
|
<div class="chevron left" id="prev-btn">‹</div>
|
||||||
|
<div class="chevron right" id="next-btn">›</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
let currentData = null;
|
let currentData = null;
|
||||||
|
|
||||||
@ -33,6 +58,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('random-img').addEventListener('click', loadRandom);
|
document.getElementById('random-img').addEventListener('click', loadRandom);
|
||||||
|
document.getElementById('prev-btn').addEventListener('click', function() {
|
||||||
|
if (currentData && currentData.previous) loadInfo(currentData.previous);
|
||||||
|
});
|
||||||
|
document.getElementById('next-btn').addEventListener('click', function() {
|
||||||
|
if (currentData && currentData.next) loadInfo(currentData.next);
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
if (e.code === 'Space') {
|
if (e.code === 'Space') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user