Skip to content

Commit 5bddba1

Browse files
committed
feat: add scrolling feature on gallery with js
1 parent 7c10cd9 commit 5bddba1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ <h2>Contact Me</h2>
109109
<section>
110110
<h2>Gallery</h2>
111111
<div class="gallery-wrapper">
112-
<button class="scroll-button left"><</button>
113-
<div class="gallery">
112+
<button class="scroll-button left" onclick="scrollGallery(-1)"><</button>
113+
<div class="gallery" id="galleryContainer">
114114
<div class="gallery-item">
115115
<img src="./profile.jpg" height="200px" width="300px" />
116116
</div>
@@ -148,11 +148,12 @@ <h2>Gallery</h2>
148148
<img src="./suti.jpg" height="200px" width="300px" />
149149
</div>
150150
</div>
151-
<button class="scroll-button right">></button>
151+
<button class="scroll-button right" onclick="scrollGallery(1)">></button>
152152
</div>
153153
</section>
154154
<footer>
155155
<p>&copy; 2025, Momi Foundation</p>
156156
</footer>
157+
<script src="script.js"></script>
157158
</body>
158159
</html>

script.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
function scrollGallery(direction) {
3+
const galleryContainer = document.getElementById('galleryContainer');
4+
const scrollAmount = 320;
5+
galleryContainer.scrollLeft += direction * scrollAmount;
6+
}
7+
8+
// can add auto-scroll in every 3 seconds
9+
setInterval(() => {
10+
scrollGallery(1);
11+
}, 3000);

0 commit comments

Comments
 (0)