Image Slideshow

Home / Web Code Snippet / Image Slideshow

Image Slideshow


https://youtube.com/shorts/LEnTiOqyZBI?si=Wlodo0T1cwaxWs9l

HTML CODE:-

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
<div class="container">
    <div class="main-img">
        <img src="https://media.istockphoto.com/id/1030858032/photo/interior-of-the-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=1w9yV19gCrvZwVtMEnWgIK82xTwSNRA8ekkfxGKb1tI=">
    </div>
    <div class="slides">
        <img src="https://media.istockphoto.com/id/1030858032/photo/interior-of-the-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=1w9yV19gCrvZwVtMEnWgIK82xTwSNRA8ekkfxGKb1tI=">
        <img src="https://media.istockphoto.com/id/1021722910/photo/interior-of-the-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=J3iatFOubM1jryGVKog_0gEbg5MWeXSBox-FPyql_eU=">
        <img src="https://media.istockphoto.com/id/946825572/photo/interior-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=i8XOm-15uTwY8kK4frNUH6zmJTml4q7-75ujDeWzzMQ=">
        <img src="https://media.istockphoto.com/id/1048084228/photo/interior-of-the-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=nUQxw_0GoSfkhryMoQCSS-SHul2hgoNH3uopOmnlyK4=">
        <img src="https://media.istockphoto.com/id/680409116/photo/interior-living-room-3d-illustration.jpg?s=612x612&w=0&k=20&c=7vTAeApK0U_UvIzERkaV0CtP0bJxq0OLTtp5kE_03xE=">
    </div>
</div>
<-- jquery link -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>

CSS CODE:-

      body{
            padding: 0px;
            margin: 0px;
            min-height: 100vh;
            background: black;
            overflow: hidden;
        }
        .container{
            position: relative;
            height: 400px;
            width: 600px;
            margin: 50px auto;
            overflow: hidden;
        }
        .container .main-img{
            position: absolute;
            top: 0;
            left: 0;
            border: 2px solid white;
            height: calc(80% - 10px);
            width: calc(100% - 3px);
        }
        .container .main-img img{
            width: 100%;
            height: 100%;
            object-fit: cover;

        }
        .container .slides{
            position: absolute;
            left: 0;
            bottom: 2px;
            width: 100%;
            height: calc(20% - 5px);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .container .slides img{
            height: 100%;
            width: calc(20% - 5px);
            border: 2px solid white;
            object-fit: cover;
            cursor: pointer;
            transition: 0.5s;
        }
        .container .slides img:hover{
            filter: grayscale();
        }

JS CODE:-

$(".container .slides img").click(function(){
        var img_url = $(this).attr('src');
        $(".main-img img").attr('src',img_url);
    });