I have a project and I have a trouble to fix this, my problem here is that my image options is moving up and down whenever I point my cursor to my image options it affects my descriptions. What should I do to fix this? I’m just starting out, so I appreciate your understanding.
I just want to fix image option to move up and down whenever I point the other images and to not affect the descriptions.
Here is the output
Here is my code.
:root {
--text-dark: #000000;
--text-light: #727274;
--extra-light: #f3f4f6;
--max-width: 1200px;
--header-font: "Montserrat", sans-serif;
--text-font: "Poppins", sans-serif;
}
body {
margin: 0;
padding: 0;
background-image: url('backg5.png');
background-size: cover;
background-position: center 10px;
background-attachment: fixed;
color: white;
overflow-x: hidden;
padding-top: 80px;
}
header {
display: flex;
position: fixed;
justify-content: center;
align-items: center;
top: 0;
width: 100%;
z-index: 1000;
transition: top 0.3s ease-in-out;
color: white;
background: hsl(0, 100%, 100%);
box-shadow: -4px 0 6px rgba(0, 0, 0, 0.1), 4px 0 6px rgba(0, 0, 0, 0.1);
padding: 10px 15px;
}
.logo {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
}
.logo img {
max-width: 120px;
margin-top: 5px;
}
.product-container {
position: absolute;
display: inline-block;
align-items: center;
justify-content: flex-start;
transform: translateY(-50%);
left: 40px;
top: 50%;
}
.product-icon {
font-size: 30px;
color: green;
}
.dropdown {
position: relative;
display: inline-block;
margin-left: auto;
}
.dropdown-content {
display: none;
position: absolute;
margin-left: auto;
background-color: #f9f9f9;
width: 1260px;
top: 71%;
padding: 0;
left: 0;
z-index: 1000;
transition: opacity 0.3s ease, visibility 0.3s ease;
border-radius: 8px;
max-height: 160px;
overflow-y: auto;
}
.dropdown:hover .dropdown-content {
display: block;
padding-top: 3px;
background-color: #f9f9f9;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.15);
opacity: 1;
visibility: visible;
}
.dropdown-content:hover {
display: block;
opacity: 1;
visibility: visible;
}
.dropdown:hover .dropdown-content {
background-color: whitesmoke;
}
.container {
display: flex;
overflow-x: auto;
margin: 10px;
scroll-padding: 0px;
gap: 10px;
max-height: 100vh;
overflow-y: hidden;
}
.container::-webkit-scrollbar {
display: block;
}
.container::-webkit-scrollbar-track {
background-color: #AAB99A;
border-radius: 10px;
}
#Container {
display: flex;
scroll-snap-type: x mandatory;
}
.item {
flex: 0 0 auto;
}
.category {
width: 100%;
max-width: 300px;
height: auto;
border-radius: 5px;
}
.product-category {
width: 100px;
height: 100px;
object-fit: contain;
gap: 2px;
border-radius: 10px;
transition: transform 0.3s ease, box-shadow 0.3s ease;
margin-bottom: 10px;
}
.product-category:hover {
transform: scale(1.1);
padding: 5px;
z-index: 10;
}
.page-body {
font-family: var(--header-font);
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 90vh;
padding: 5px;
}
.page-container {
background-color: #fff;
display: flex;
flex-direction: column;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
padding: 30px;
max-width: 1000px;
width: 100%;
margin-bottom: 0;
padding-bottom: 0;
gap: 10px;
}
@media (min-width: 768px) {
.page-container {
flex-direction: row;
}
}
.image-gallery {
flex: 0.9;
text-align: left;
}
.image-gallery img {
max-width: 100%;
height: auto;
}
.image-wrapper {
max-width: 450px;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.thumbnail-wrapper {
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
padding: 5px 0;
width: 100%;
}
.thumbnail-row {
display: flex;
gap: 4px;
overflow-x: auto;
height: 80px;
scroll-behavior: smooth;
pointer-events: auto;
scrollbar-width: none;
scroll-snap-type: x mandatory;
padding-top: 8px;
padding-left: 0;
padding-right: 0;
align-items: center;
}
.thumbnail-row::-webkit-scrollbar {
display: none;
}
.thumbnail-row img {
width: 75px;
height: 75px;
border: 2px solid transparent;
transition: border 0.2s ease, transform 0.2s ease;
cursor: pointer;
pointer-events: auto;
scroll-snap-align: start;
box-sizing: border-box;
object-fit: cover;
flex-shrink: 0;
margin-left: 0;
margin-right: 0;
position: relative;
z-index: 1;
display: block;
}
.thumbnail-row img:hover {
border-color: #5F8B4C;
z-index: 1;
}
/* Selected state */
.thumbnail-row img.selected {
border-color: #5F8B4C;
}
.arrow {
position: absolute;
top: 50%;
transform: translateY(-50%);
border: none;
font-size: 30px;
padding: 8px;
cursor: pointer;
z-index: 10;
color: white;
background-color: rgba(87, 83, 83, 0.428);
}
.arrow img {
width: 25px;
height: 25px;
pointer-events: none;
}
.arrow.left {
position: absolute;
left: -0px;
}
.arrow.right {
position: absolute;
right: -0px;
}
.product-details {
flex: 1;
padding-top: 10px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
text-align: left;
gap: 10px;
margin-top: 0;
padding-left: 0;
}
@media (min-width: 768px) {
.product-details {
padding-left: 0px;
padding-top: 0;
flex-direction: column;
}
}
.product-details h2 {
color: var(--text-dark);
font-family: var(--header-font);
text-align: left;
}
.price {
color: #5F8B4C;
font-weight: bold;
font-family: var(--header-font);
font-size: large;
text-align: left;
}
.description {
margin: 15px 0;
color: #666;
font-family: var(--text-font);
font-size: 16px;
text-align: left;
}
.color-name {
color: var(--text-dark);
font-weight: bold;
text-align: left;
}
.colors {
margin: 10px 0;
flex-wrap: wrap;
gap: 10px;
overflow: hidden;
text-align: left;
}
.color-option {
display: inline-block;
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 10px;
cursor: pointer;
transition: transform 0.3s ease;
transform-origin: center center;
border: 2px solid #EFF3EA;
flex-shrink: 0;
}
.color-option:hover {
outline: 2px solid #EFF3EA;
outline-offset: 0px;
transform: scale(1.2);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GOOJODOQ</title>
<link rel="stylesheet" href="productin2.css" />
<!-- External Scripts -->
<script src="https://unpkg.com/scrollreveal"></script>
<script src="main.js" defer></script>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Antonio:wght@700&family=Russo+One&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Teko:wght@400;700&family=Oswald:wght@400;700&family=Rajdhani:wght@400;700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Montserrat:wght@400;700&family=Raleway:wght@400;700&display=swap" rel="stylesheet" />
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" rel="stylesheet" />
</head>
<body>
<header>
<div class="logo">
<img src="goojodoq-logo.png" alt="Goojodoq Logo" />
</div>
<div class="product-container">
<!-- Product Dropdown -->
<div class="dropdown">
<a href="#" id="product-link">
<i class="fas fa-shopping-cart product-icon"></i>
</a>
<div class="dropdown-content">
<div class="container" id="Container">
<!-- Product Items -->
<div class="item"><img src="fan.png" alt="Fan" class="product-category" /></div>
<div class="item"><img src="mouse.png" alt="Mouse" class="product-category" /></div>
<div class="item"><img src="stylus_pen.png" alt="Stylus Pen" class="product-category" /></div>
<div class="item"><img src="USB.png" alt="USB" class="product-category" /></div>
<div class="item"><img src="keyboard.png" alt="Keyboard" class="product-category" /></div>
<div class="item"><img src="speaker.png" alt="Speaker" class="product-category" /></div>
<div class="item"><img src="fan.png" alt="Fan" class="product-category" /></div>
<div class="item"><img src="mouse.png" alt="Mouse" class="product-category" /></div>
<div class="item"><img src="stylus_pen.png" alt="Stylus Pen" class="product-category" /></div>
<div class="item"><img src="USB.png" alt="USB" class="product-category" /></div>
<div class="item"><img src="keyboard.png" alt="Keyboard" class="product-category" /></div>
<div class="item"><img src="speaker.png" alt="Speaker" class="product-category" /></div>
</div>
</div>
</div>
</div>
</header>
<main>
<div class="page-body">
<div class="page-container">
<!-- Image Gallery -->
<div class="image-gallery">
<div class="image-wrapper">
<img id="mainImage" src="/pictures/1.jpg" alt="Headphones" />
<div class="thumbnail-wrapper">
<button class="arrow left" onclick="scrollThumbnails(-1)">‹</button>
<div class="thumbnail-row" id="thumbnailRow">
<img src="/pictures/1.jpg" onclick="changeImage(this)" />
<img src="/pictures/2.jpg" onclick="changeImage(this)" />
<img src="/pictures/3.jpg" onclick="changeImage(this)" />
<img src="/pictures/4.jpg" onclick="changeImage(this)" />
<img src="/pictures/5.jpg" onclick="changeImage(this)" />
<img src="/pictures/7.jpg" onclick="changeImage(this)" />
</div>
<button class="arrow right" onclick="scrollThumbnails(1)">›</button>
</div>
</div>
</div>
<!-- Product Details Section -->
<div class="product-details">
<h2>Beats Solo3 Wireless</h2>
<div class="price">$999.99</div>
<div class="description">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="colors">
<div class="color-name">Available Colors</div><br>
<div class="color-option" style="background-color: white;"></div>
<div class="color-option" style="background-color: pink;"></div>
<div class="color-option" style="background-color: purple;"></div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
document.addEventListener("DOMContentLoaded", function () {
let lastScrollTop = 0;
const header = document.querySelector("header");
window.addEventListener("scroll", function () {
const currentScroll = window.pageYOffset || document.documentElement.scrollTop;
header.style.top = currentScroll > lastScrollTop ? "-100px" : "0";
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
});
const container = document.getElementById("Container");
if (container) {
container.addEventListener("wheel", function (event) {
event.preventDefault();
this.scrollLeft += event.deltaY;
});
}
function changeImage(imgElement) {
const mainImage = document.getElementById("mainImage");
if (mainImage) {
mainImage.src = imgElement.src;
}
document.querySelectorAll(".thumbnail-row img").forEach(img => {
img.classList.remove("selected");
});
imgElement.classList.add("selected");
}
function changeQty(change) {
const qtyElement = document.getElementById("quantity");
if (qtyElement) {
let qty = parseInt(qtyElement.textContent) || 1;
qty = Math.max(qty + change, 1);
qtyElement.textContent = qty;
}
}
const scrollContainer = document.getElementById("thumbnailRow");
const leftArrow = document.querySelector(".arrow.left");
const rightArrow = document.querySelector(".arrow.right");
function scrollThumbnails(direction) {
const scrollAmount = 100;
if (scrollContainer) {
scrollContainer.scrollBy({
left: direction * scrollAmount,
behavior: "smooth"
});
}
}
if (leftArrow && rightArrow && scrollContainer) {
leftArrow.addEventListener("click", () => scrollThumbnails(-1));
rightArrow.addEventListener("click", () => scrollThumbnails(1));
}
const mainImage = document.getElementById("mainImage");
const thumbnails = document.querySelectorAll(".thumbnail-row img");
thumbnails.forEach(thumbnail => {
thumbnail.addEventListener("mouseover", () => {
// Set as main image
if (mainImage) {
mainImage.src = thumbnail.src;
}
thumbnails.forEach(img => img.classList.remove("selected"));
// Add selected to hovered
thumbnail.classList.add("selected");
});
});
window.img = function (src) {
const mainImage = document.getElementById("mainImage");
if (mainImage) {
mainImage.src = src;
}
};
if (typeof ScrollReveal !== "undefined") {
ScrollReveal().reveal(".page-body", {
origin: "bottom",
distance: "50px",
duration: 1000,
delay: 100,
reset: true
});
} else {
console.warn("ScrollReveal is not defined.");
}
window.changeImage = changeImage;
window.changeQty = changeQty;
});


