Kevin Powell - CommunityKP-C
Kevin Powell - Community12mo ago
9 replies
Rebeca

Slider activation causing sudden vertical scroll

So, I have this slider where everytime I click the slider-nav to change images, the viewport top automatically aligns with the product-slider-wrapper top. Basically, causes an abrupt vertical scroll to align their tops everytime you scroll between images with a click.

The image with the front view of the glasses is what happens after I click one of the slider-nav links.

What I've already tried to solve it, but failed:

html {
    scroll-behavior: auto;
}


:target {
    position: relative;
    top: 0; 
}


The HTML is with the images, since the message was too long and I couldn't post it.

The CSS:

.product-page-item {
    display: flex;
    gap: 5rem;
    padding: 5rem 0 0 0;
}

.product-slider-wrapper {
    position: relative;
    /* max-width: 48rem; */
    border: solid 1px var(--clr-neutral-600);
    border-radius: 20px;
    z-index: 1;
}

.product-slider {
    display: flex;
    aspect-ratio: 1 / 1;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    border-radius: 1rem;
    -ms-overflow-style: none; /* hide scrollbar IE and Edge */
    scrollbar-width: none; /* hide scrollbar Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.slider::-webkit-scrollbar {
    display: none;
}

.product-slider img {
    flex: 1 0 100%; /* flex grow, flex shrink, flex basis */
    scroll-snap-align: start;
    object-fit: cover;
    border-radius: 20px;
}

.slider-nav {
    display: flex;
    column-gap: 1rem;
    position: absolute;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

.slider-nav a {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    background-color: var(--clr-neutral-900);
    opacity: 0.5;
    transition: opacity ease 250ms;
}

.slider-nav a:hover {
    opacity: 1;
}


Can someone, please, help me? 🥲
before.PNG
after.PNG
html.PNG
Was this page helpful?