Hello developers, today in this blog, you'll learn to create a Responsive Rotating Image Slider using HTML, CSS & JavaScript.
The Image Slider is also called Image Carousel or Slideshow. The Image Slider may be the convenient way to display the changing or sliding images one by one on your website. In the Image Slider, the images will slide one by one manually and also automatically.
In this blog (Responsive Rotating Image Slider), there is an image at the center of the webpage which rotates automatically and continuously. The Rotating Image Slider is made responsive by using the CSS media query property.
The source code of this Responsive Rotating Image Slider is given below, if you want the source code of this program, you can copy it. You can use this Responsive Rotating Image Slider on your project and take this to the subsequent level.
Responsive Rotating Image Slider [Source Code]
To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background-color: #000;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
perspective: 1000px;
overflow: hidden;
}
.slider {
position: relative;
height: 400px;
width: 700px;
transform-style: preserve-3d;
animation: rotate 4s linear infinite;
border: 10px solid #fff;
}
.slide {
opacity: 0;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.slide.visible {
opacity: 1;
}
@keyframes rotate {
0% {
transform: rotateY(90deg);
}
47%, 53% {
transform: rotateY(270deg);
}
94%, 100% {
transform: rotateY(450deg);
}
}
.slide img {
object-fit: cover;
height: 100%;
width: 100%;
}
@media screen and (max-width: 500px) {
.slider {
height: 280px;
width: 280px;
}
}
.credit{
text-align: center;
color: #fff;
margin-top: 10px;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.credit a{
text-decoration: none;
color:#fff;
font-weight: bold;
}
const slides = document.querySelectorAll('.slide');
const slider = document.querySelector('.slider');
let activeSlide = 0;
slider.addEventListener('animationstart', () => {
setInterval(changeSlide, 2000);
});
function changeSlide() {
slides[activeSlide].classList.remove('visible');
activeSlide++;
if(activeSlide >= slides.length) {
activeSlide = 0;
}
slides[activeSlide].classList.add('visible');
}
Thank you for reading our blog. If you face any problem creating this Responsive Rotating Image Slider using HTML, CSS & JavaScript, then contact us or comment us. We'll try to provide a solution to your problem as soon as possible.
إرسال تعليق
Thank you
Learning robo team