Logo

dev-resources.site

for different kinds of informations.

SLIDER ANIMATION HELP

Published at
7/19/2024
Categories
css
html
slider
javascript
Author
mixertmk_mixertime_0d7de2
Categories
4 categories in total
css
open
html
open
slider
open
javascript
open
Author
25 person written this
mixertmk_mixertime_0d7de2
open
SLIDER ANIMATION HELP

I have a slider with 5 images and the images have different sizes, I am trying to make the resizing animations between them work well

In this code I have animations placed on each image, the one I am interested in correcting is particularly the one for the "medium" images, the animation is prepared to go from "small" to "medium".
You can do that if I move it to the left, that is, if we have this order

1 | 2 | 3 | 4 | 5
it would look like this moving it to the left:
2 | 3 | 4 | 5 | 6.

Given this example situation, the image that has the correct animation is 5, since it goes from "small" to "medium", but the one that looks bad is 3, it would have to go from "large" to " medium".

`

<!DOCTYPE html>









Image Slider

<br>
body {<br>
font-family: Arial, sans-serif;<br>
background-color: #f0f0f0;<br>
display: flex;<br>
justify-content: center;<br>
align-items: center;<br>
height: 100vh;<br>
margin: 0;<br>
}</p>
<div class="highlight"><pre class="highlight plaintext"><code> .slider-container {
width: 80%;
overflow: hidden;
position: relative;
height: 400px;
}
.slider {
    display: flex;
    transition: transform 0.5s ease-in-out;
}

.slide {
    flex: 0 0 20%;
    box-sizing: border-box;
    transition: transform 0.5s ease;
}

.slide h2, .slide p {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.slide.hide-text h2,
.slide.hide-text p {
    display: none;
}

.show-text h2, .show-text p {
    animation: fadeIn .9s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

img {
    width: 100%;
    display: block;
    margin: 5px 0;
}

.small {
    margin-top: 48px;
    animation: fadeOn .5s ease forwards;
}

@keyframes fadeOn {
    from {
        scale: 0.8;
    }
    to {
        scale: .7;
    }
}

.medium {
    margin-top: 67px;
    animation: fadeOn-2 .5s ease forwards;
}

@keyframes fadeOn-2 {
    from {
        scale: 0.7;
    }
    to {
        scale: .9;
    }
}

.large {
    margin: 0 4px;
    animation: fadeOn-3 .5s ease forwards;
}

@keyframes fadeOn-3 {
    from {
        scale: 0.85;
    }
    to {
        scale: 1;
    }
}



.nav {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    transform: translateY(-50%);
}

.prev, .next {
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
    z-index: 1;
}

div {
    display: flex;
    flex-direction: column;
}

h2,p {
    text-align: center;
}

p {
    font-size: 10px;
    margin-top: -20px;
}
Enter fullscreen mode Exit fullscreen mode

&lt;/style&gt;
</code></pre></div>
<p></head><br>
<body><br>
<section class="slider-container"><br>
<nav class="slider"><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image1.jpg" alt="Image 1"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image2.jpg" alt="Image 2"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image3.jpg" alt="Image 3"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image4.jpg" alt="Image 4"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image5.jpg" alt="Image 5"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image6.jpg" alt="Image 6"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image7.jpg" alt="Image 7"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>SERVICES</h2><br>
<img src="image8.jpg" alt="Image 8"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>TITLE</h2><br>
<img src="image9.jpg" alt="Image 9"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
<div class="slide"><br>
<h2>TITLE</h2><br>
<img src="image10.jpg" alt="Image 10"><br>
<p>Create an unforgettable engagement experience! Not only capture stunning photos and videos at a location of your dreams, but we&#39;ll also treat you like VIPs afterward. A car service will pick you up and take you wherever you&#39;d like to continue celebrating.</p><br>
</div><br>
</nav><br>
<nav class="nav"><br>
<button class="prev" onclick="plusSlides(-1)">&#10094;</button><br>
<button class="next" onclick="plusSlides(1)">&#10095;</button><br>
</nav><br>
</section></p>
<div class="highlight"><pre class="highlight plaintext"><code>&lt;script&gt;
</code></pre></div>
<p>let slideIndex = 0;<br>
const slides = document.getElementsByClassName(&quot;slide&quot;);<br>
const slider = document.querySelector(&quot;.slider&quot;);<br>
const slidesToShow = 5;<br>
const slideWidth = 100 / slidesToShow;</p>

<p>function plusSlides(n) {<br>
slideIndex += n;<br>
if (slideIndex &gt; slides.length - slidesToShow) {<br>
slideIndex = 0;<br>
} else if (slideIndex &lt; 0) {<br>
slideIndex = slides.length - slidesToShow;<br>
}<br>
showSlides();<br>
}</p>

<p>function showSlides() {<br>
slider.style.transform = &#39;translateX(&#39; + (-slideIndex * slideWidth) + &#39;%)&#39;;</p>
<div class="highlight"><pre class="highlight plaintext"><code>for (let i = 0; i &lt; slides.length; i++) {
slides[i].classList.remove("small", "medium", "large", "hide-text", "show-text");

if (i === (slideIndex + 2) % slides.length) {
    slides[i].classList.add("large");
    slides[i].classList.add("show-text");
} else if (i === (slideIndex + 1) % slides.length || i === (slideIndex + 3) % slides.length) {
    slides[i].classList.add("medium", "hide-text");
} else if (i === slideIndex || i === (slideIndex + 4) % slides.length) {
    slides[i].classList.add("small", "hide-text");
} else {
    slides[i].classList.add("small", "hide-text");
}
Enter fullscreen mode Exit fullscreen mode

}
</code></pre></div>
<p>}</p>

<p>showSlides();<br>
</script><br>
</body><br>
</html><br>
`</p>

slider Article's
30 articles in total
Favicon
infinity slider
Favicon
Build A Stunning Animated Travel Image Slider Using Html, Css, And JavaScript!
Favicon
Slider in Flutter
Favicon
SLIDER ANIMATION HELP
Favicon
Making a slider puzzle in Java Script
Favicon
#LearnedToday: Slider in pure CSS
Favicon
Flutter - Triangular CAROUSEL Slider
Favicon
looking for a slider package for angular
Favicon
Creating a Slider using Next.js and CSS
Favicon
Create Dynamic Image Slider with PHP and MySQL
Favicon
A step-by-step guide to creating a beautiful slider with Swiper and React
Favicon
Animating using sliders in JavaFX and SceneBuilder
Favicon
Product Gallery Slider for WooCommerce
Favicon
What is a slider and why you should slider on your website?
Favicon
Kaydırıcı robot
Favicon
Basic JavaScript slider ready source
Favicon
Pure CSS Vertical Image Slider Using Only HTML & CSS
Favicon
How to make a simple slider component in React
Favicon
Responsive Image slider using Owl Carousel | HTML & CSS
Favicon
Simple Slider on a pure JavaScript
Favicon
Image Slideshow HTML CSS
Favicon
Ngx Slick Carousel In Angular Material Card with Custom Arrows
Favicon
How to make a Full Slider with javascript in 10 mins
Favicon
Let's build a slider from scratch in React Native
Favicon
Elegant & Beautiful Testimonial Sliders
Favicon
Choppy Slider: The Styles
Favicon
Flutter. A Quarter Round Slider.
Favicon
VueJS: Double range slider component
Favicon
Styling Range Sliders with CSS
Favicon
AWS – Using Multiple (Staging, UAT and Production) Accounts Under AWS Organization

Featured ones: