Skip to main content

SLIDER USING HTML, CSS, and Javascript

WATCH THE YOUTUBE PREVIEW:




MOVING SLIDER:

The moving slider contains two divs. The first div displays the full image and the second one has the selection tabs. On clicking them our display image moves to the specified image. 

HTML:

    <div id="main">
        <div id="show">
            <img src="a1.jpg">
            <img src="a2.jpg">
            <img src="a3.jpg">
            <img src="a4.jpg">
        </div>
        <div id="select">
            <div class="item">
                <a href="#" onclick="allot(1);">
                    <img src="a1.jpg" alt="">
                </a>
            </div>
            <div class="item">
                <a href="#" onclick="allot(2);">
                    <img src="a2.jpg" alt="">
                </a>
            </div>
            <div class="item">
                <a href="#" onclick="allot(3);">
                    <img src="a3.jpg" alt="">
                </a>
            </div>
            <div class="item">
                <a href="#"onclick="allot(4);">
                    <img src="a4.jpg" alt="" >
                </a>
            </div>
            
        </div>
    </div>


CSS:

        body{
            background-image: linear-gradient(to right,red,orange);
        }
        img{
            width: 100%;
        }
        #main{
            width: 30%;
            overflow: hidden;
            position: absolute;
            left: 480px;
            top: 73px;
            border: solid red;
            box-shadow: 10px 5px 10px 4px black;
        }
        #show{
            width: 100%;
            display: flex;
            transition: 0.5s all ease-in-out;
            height: 60vh;
        }
        #select{
            display: flex;
        }
        .item{
            margin: 0.3rem;
            margin-right: 0rem;
        }
        .item:hover{
            border: solid white;
        
        }


JAVASCRIPT:

        var imid = 1;
        const wid = document.querySelector("#show img:first-child").clientWidth;
        var i;
        function allot (i){
            imid = i;
            slide();
        }
        function slide(){
            const wid = document.querySelector("#show img:first-child").clientWidth;
            var dis = -(imid-1)*wid;
            document.querySelector("#show").style.transform = `translateX(${dis}px)`;
        }

The display image div contains two divs with the same dimensions and which fixes them. When we click on the image in select div a particular position number is allocated to them using allot function and further this accounts for the slide function which translates the display div to opposite direction of the product of position number and width of first image in display. 


Comments

Popular posts from this blog

Aesthetic Login & Sign-up page | HTML, CSS, & Javascript

Take a tour of our final login and sign-up page. HTML CODE: We create three divs- the first one to select from the option of either login or sign-up containing two buttons, the second one with a form for sign-up, and the third one for login. To all the buttons on the page, we provide a single class and for both the forms, a single class is given. CODE:     <div id="options">         <button class="but" style="margin-top: 20px;" onclick="appear();">Login</button>         <button class="but" onclick="sinapp();">Sign-Up</button>         <p>Use G-mail or Facebook account</p>     </div>     <div id="sign" class="formin">         <form id="sin-cont">             <input type="text" name="fn" placeholder="Enter Your First Name" required>             <input typ...

CHAPTER SIX: THE FLAMES

MAYOR'S OFFICE  Gryffin Scout smoked heavily looking out of the window at the moon. "What are my orders sir," said a cop in the room, "I want to meet JJ Warren, as quick as possible, things are getting insane, I can't take further risks, let's see what he has to offer me, contact him tomorrow morning," said Scout.  THE WAREHOUSE From the window at the roof of the warehouse, a can of fuel fell to the floor, after which a matchstick fell, raising flames in the entire space. Warren looked at the rising flames anxiously when he ran to a corner saving himself from the rising flames approaching him. "Why are you doing this?" Warren shouted in a rage, "I will kill you JJ Warren, I promise you, this will be your end, and I am honored to kill such a worthy opponent tonight!" said the echo. "Leave my friends alone, they are innocent, don't hurt them!" shouted Warren, "They will die before you, I assure you of that, and this w...

CHAPTER SIX: THE MASK

 Louis Luther was a good man. He used to wake up a six, take a bath, his wife prepared breakfast for him, and his lunch for a break from work in the afternoon. Louis while walking down the street to his workstation used to greet every single man he encountered in his way. He used to joke with kids, sometimes play with them in the streets. His own kids were also sweet, he had a daughter who was six and a son who was three years old. Louis had one principle, do good and have good. So he used to do good for everyone, wanted everyone to smile because of him but sometimes he didn't get the results. Sometimes, people would shut him up but Louis would never give up. That's what a good man is, a pure soul with a golden heart. Louis just had one problem in his life, his friend Bob Harley. Bob was rude and loud to Louis since the beginning of this business. Sitting on the main counter as the owner he would order Louis to work, though this work belonged to both of them equally. Louis stil...