Skip to main content

How to Create a Image Slider Using HTML, CSS and JS

 

#html #css #foryou #world #happy # website #webdesign #webdeveloper #how to #howto #trending #viral #srilanka #youtube #tiktok #blog  #howtocreate #Javascript #image #imageuploader #imageslider #howtocreateimageslider 




🎥 Ready to level up your web development skills? Join us in this tutorial where we guide you through the process of creating a dynamic Image Slider using HTML, CSS, and JavaScript! 🚀 Explore the magic of coding as we break down each step, empowering both beginners and seasoned developers to enhance their projects with a stunning image carousel. From seamless transitions to customizable features, this tutorial covers it all. Elevate your website's visual appeal and engage your audience with an eye-catching image slider. Let's bring your designs to life! 💻🌟

Don't forget to like, share, and subscribe for more web development tutorials and tips. If you have any questions or need further assistance, feel free to leave a comment, and we'll be happy to help you out. Happy coding! 


index.html  
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Slider</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://kit.fontawesome.com/b186863b7d.js"
    crossorigin="anonymous"></script>
</head>
<body>
 <div class="container">
    <div class="slide">
        <div class="item" style="background-image: url(Image/Adam\'s\ peak\ \ sripadaya.jpg);">
            <div class="content">
                <div class="name">Siripadaya | Adam's Peak</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>

        <div class="item" style="background-image: url(Image/dunhinda\ ella.jpg);">
            <div class="content">
                <div class="name">Dunhinda Ella</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>

        <div class="item" style="background-image: url(Image/lotus-tower.jpg);">
            <div class="content">
                <div class="name">Lotus Tower</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>


        <div class="item" style="background-image: url(Image/nilaveli\ beach.jpg);">
            <div class="content">
                <div class="name">Nilaveli Beach</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>


        <div class="item" style="background-image: url(Image/ruwanweli\ maha\ seya.jpg);">
            <div class="content">
                <div class="name">Ruwanweli Maha Seya</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>


        <div class="item" style="background-image: url(Image/sigiriya.png);">
            <div class="content">
                <div class="name">Sigiriya</div>
                <div class="des">Description Here....</div>
                <button>Read More...</button>
            </div>
        </div>


        <div class="item" style="background-image: url(Image/Temple\ of\ the\ tooth\ relic.jpg);">
            <div class="content">
                <div class="name"></div>
                <div class="des"></div>
                <button>Read More...</button>
            </div>
        </div>





    </div>

    <div class="button">
        <button class="previous"><i class="fa-solid fa-arrow-left"></i></button>
        <button class="next"><i class="fa-solid fa-arrow-right"></i></button>
    </div>
 </div>
<script src="script.js"></script>
</body>
</html>


style.css  

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body{
    background: #fff;
}
.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1000px;
    height: 550px;
    box-shadow: 0 30px 45px black;
}
.container .slide .item{
    width: 200px;
    height: 300px;
    position: absolute;
    top: 50%;
    transform: translate(0, -50%);
    box-shadow: 0 30px 45px gray;
    background-position: 50% 50%;
    background-size: cover;
    display: inline-block;
    transition: 0.5s;
    border-radius: 15px;
}
.slide .item:nth-child(1), .slide .item:nth-child(2){
    top: 0;
    left: 0;
    transform: translate(0,0);
    border-radius: 8px;
    width: 100%;
    height: 100%;

}
.slide .item:nth-child(3){
    left: 50%;
}
.slide .item:nth-child(4){
    left: calc(50% + 220px);
}
.slide .item:nth-child(5){
    left: calc(50% + 440px);
}
.slide .item:nth-child(n +6){
    left: calc(50% + 660px);
    opacity: 0;
}

.item .content{
    position: absolute;
    top: 50%;
    left: 100px;
    width: 300px;
    text-align: left;
    color: #fff;
    transform: translate(0, -50%);
    font-family: Georgia, 'Times New Roman', Times, serif;
    display: none;
}
.slide .item:nth-child(2) .content{
    display: block;
}
.content .name{
    font-size: 35px;
    text-transform: uppercase;
    font-weight: bold;
    opacity: 0;
    animation: animate 1s ease-in-out 1 forwards;
}
.content .des{
    margin-top: 10px;
    margin-bottom: 20px;
    opacity: 0;
    animation: animate 1s ease-in-out 0.3s 1 forwards;
}
.content button{
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    animation: animate 1s ease-in-out 0.6s 1 forwards;
}
@keyframes animate {
    from{
        opacity: 0;
        transform: translate(0, 100px);
        filter: blur(30px);
    }
    to{
        opacity: 1;
        transform: translate(0);
        filter: blur(0);
    }
}
.button{
    width: 100%;
    text-align: center;
    position: absolute;
    bottom: 20px;
}
.button button{
    margin: 0 5px ;
    border: 1px solid #000;
    transition: 0.2s;
    width: 40px;
    height: 35px;
    border-radius: 8px;
    cursor: pointer;
    border-radius: 3px;
}  
.button button:hover{
    background: gray;
    color: black;
}





script.js 

let next = document.querySelector('.next')
let previous = document.querySelector('.previous')
next.addEventListener('click', function(){
    let items = document.querySelectorAll('.item')
    document.querySelector('.slide').appendChild(items[0])
})
previous.addEventListener('click', function(){
    let items = document.querySelectorAll('.item')
    document.querySelector('.slide').prepend(items[items.length - 1])
})









































Comments

Popular posts from this blog

How to Build Your Own Image Uploader using HTML, CSS, and JS Tutorial

    Welcome to our step-by-step tutorial on creating your own image uploader using #html  , #css  , and JavaScript. In this video, we'll guide you through the process of building a simple yet effective image uploader for your web projects. With just a few lines of code, you'll learn how to create a user-friendly interface that allows users to upload images seamlessly. Whether you're a beginner or an experienced developer looking to enhance your skills, this tutorial is perfect for you. Follow along and empower yourself to create dynamic web applications with ease! Don't forget to like, share, and subscribe for more coding tutorials. Let's get started!  index.html   <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Drag & Drop Image Uploader </ title >...

Create an Animated Switch with HTML and CSS in 2024

  Create an Animated Switch with HTML and CSS in 2024 Learn how to create an animated switch using HTML and CSS in 2024! This tutorial will guide you through the process of building a sleek and modern switch element for your website. Enhance your web development skills and stay up-to-date with the latest design trends by mastering this technique. Watch now to level up your front-end development game!  index.html  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < link rel = "stylesheet" href = "style.css" > </ head > < body >     < label class = "switch" >         < input type = "checkbox" checked = "checked" >         < div class = "button" >  ...

Animated Switch

    index.html <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < link rel = "stylesheet" href = "style.css" > </ head > < body >     < label class = "switch" >         < input class = "cb" type = "checkbox" />         < span class = "toggle" >           < span class = "left" > off </ span >           < span class = "right" > on </ span >         </ span >       </ label >       </ body > </ html > style.css  /* The switch - the box around the slider */ .switch {     font-size : 17px ; ...