Navigational Arrows within a JQuery Image Carousel

I've successfully developed an image slider using a combination of HTML, CSS, and JS (Jquery). The slider consists of 5 images that users can navigate between using arrow buttons. Everything is functioning correctly so far, but I'm encountering an issue with the right arrow button disappearing prematurely. Instead, I want it to disappear only once the last image has been reached. Any suggestions on how to resolve this problem would be greatly appreciated. Thank you in advance!

Image of the slider https://i.sstatic.net/pWFCN.png

Image illustrating my issue (the right arrow vanishes as soon as the second image is reached, whereas it should only happen when reaching the final image). https://i.sstatic.net/RbZS6.jpg

Provided below is the code snippet

$(document).ready(function() {
    $('.next').on('click',function(event) {
        var images = $('.slider-inner').find('img');
        var currentImg = $('.active')
        var nextImg = currentImg.next();
        var lastImg = images.last();
        var rightArrow = $('.next');

        images.not(':first').hide();

        if (nextImg.length) {
            currentImg.removeClass('active');
            nextImg.addClass('active');
            nextImg.fadeIn();
        }
        
        if (lastImg.length) {
            rightArrow.hide();
        }
       
        event.preventDefault();
    });

    $('.prev').on('click',function() {
        var currentImg = $('.active')
        var prevImg = currentImg.prev();

        if (prevImg.length) {
            currentImg.removeClass('active');
            prevImg.addClass('active');
        }
        

        
    });
});
*,*::before,*::after {box-sizing: border-box;}

body {
    background-image: url("../images/bg.png");
    background-size: 100%;
    font-size: 100%;
    font-family: "Roboto",sans-serif;
    color: white;
    
}

.container {
    max-width: 1250px;
    margin: 0 auto;
    overflow: auto;
}


img {
    max-width: 100%;
    height: auto;
}


a {
    color: #fff;
    text-decoration: none;
}



.slider-inner {
    margin: 0 auto;
    max-width: 1200px;
    max-height: 675px;
    position: relative;
    overflow: hidden;
    float: left;
    padding: 0.1875em;
    border: black solid 7px;
}

.slider-inner img {
    display: none;
    
}

.slider-inner img.active {
    display: inline-block;
}

.prev, .next {
    margin-top: 18.75em;
    float: left;
    cursor: pointer;
}


.prev {
    z-index: 100;
    margin-right: -2.8125em;
    position: relative;
    
}


.next {
    margin-left: -2.8125em;
    z-index: 100;
    position: relative;
}



.nadpis {
    font-weight: 400;
    text-align: center;
}

.podnadpis {
    text-align: center;
    font-weight: 100;
    font-size: 3em;
    margin-top: 2em;
}

.img-slider {
    text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Responsive Website</title>
    <link rel="stylesheet" href="css/styles2.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;400&display=swap" rel="stylesheet">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Cinzel&display=swap" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h1 class="nadpis">Interesting Things You Can Create with JS and JQuery</h1>
        <h2 class="podnadpis">Image Slider</h2>
        <div class="slider-outer">
            <img src="img-slider/arrow-left.png" alt="left arrow" class="prev">
            <div class="slider-inner">
                <img src="img-slider/john-jpg.jpg" class="active" alt="A game character witha quote saying Do you kids watch horror movies?, you never, ever, split up.">
                <img src="img-slider/butterflies-jpg.jpg" alt="A game character looking at an enthogy">
                <img src="img-slider/andrew-jpg.jpg" alt="Three characters, one from the future, one from the present and one from the past">
                <img src="img-slider/taylor-jpg.jpg" alt="Three characters, one from the future, one from the present and one from the past"">
                <img src="img-slider/vince-.jpg.jpg" alt="A bar with a guy sitting there">
                <img src="img-slider/conrad.jpg" alt="Conrad">
            </div>
            <img src="img-slider/arrow-right.png" alt="next arrow" class="next">
        </div>
    </div>
    

    <script src="javascript/jquery.js"></script>
    <script src="javascript/main.js"></script>
</body>
</html>

Answer №1

if (lastImg.hasClass("selected")) {
         rightArrow.hide();
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to modify the background hue of an upward facing triangle when a submenu is hovered over?

Access the Code on Fiddle #nav .submenu:before { content:""; position: absolute; width: 0; height: 0; border-bottom: 22px solid #b29600; border-left: 11px solid transparent; border-right: 11px solid transparent; margin: -12px ...

Enforce a line break in flexbox and display items in the next column

Is there a way to break an item in a flexbox and display it at the beginning of the next column, based on the max height of the box? See the image below for reference. .flex{ display:flex; flex-direction:column; flex-wrap:wrap; max-height:200px ...

What is the method for implementing a dropdown box with select and non-select checkboxes, similar to the example shown in the image, using AngularJS?

https://i.sstatic.net/CTx8K.jpg I am seeking assistance in incorporating the image below into a dropdown menu using angularjs ...

What strategies does Wired magazine use to create their unique thick underline link style?

Recently, I came across an interesting design choice on Wired magazine's website - they use a thick blue underline for their links that crosses over text descenders and is a different color from the text itself. You can see an example on this random p ...

Utilize Bootstrap to switch between 'collapse' and 'collapse in' depending on the device being used

I have a collapsible panel set to default "expand" (collapse in) and it is working well. However, I would like to make it "collapse" (shrink) for mobile and tablet devices. Is there any built-in feature in Bootstrap that can help me achieve this? <div ...

Utilize the dynamic backlash/Werkzeug debugger during an unsuccessful AJAX request on a TurboGears server

TurboGears offers the unique feature of "backlash," an interactive debugger within the browser that is built on the Werkzeug Debugger. When server-side debugging is enabled, in case of a request failure, an interactive web page is displayed where users can ...

Is there a way to ensure that the height of my images matches exactly with its width?

Is there a way to ensure that the height of my images always matches their width? I need the height of the images to dynamically adjust and match the width, even when the window is resized. For example, if the image width is 500px, the height should also ...

What are some ways to utilize JavaScript for expanding an HTML form?

I am in the process of developing a basic web application that allows users to create messages with attached files. multiple html file inputs using this javascript link: http://img38.imageshack.us/img38/4474/attachments.gif The functionality to "attach a ...

Trouble with image rotation in jQuery/JavaScript slideshow

For more information, you can visit and click on the Canucks icon, which is located as the third icon below "information architecture and usability." I am attempting to set up a jQuery slideshow by utilizing a template I found online. However, I am encou ...

Creating a Vibrant Progress Bar with Multiple Colors: A Step-by-Step Guide

I'm still getting the hang of things, so I apologize if my question isn't perfectly clear. What I'm trying to do is create a dynamic progress bar with multiple colors that animates upon loading the page. I've seen some examples similar ...

How to disable CSS transition on Angular 4 component initialization

I am facing a major issue with css transitions and Angular 4. The problem arises when using an external library that includes an input counter feature. Despite knowing that no additional styling is being applied to the wrapped input, the application has a ...

Enhance your Magento store with a personalized layout update

Is there a way to call a stylesheet from my skin folder instead of pointing to my base path? Right now I have <reference name="head"> <action method="addCss"> <stylesheet>yourtheme/css/red.css</stylesheet> < ...

The hyperlink within the dropdown menu in HTML code is malfunctioning

I'm currently working on my personal website using HTML and CSS with textedit. I've successfully created functional links for the main navigation menu headings, but I'm encountering issues with the dropdown options. Whenever I try to click o ...

Ways to apply background to a div element

I attempted to place an image as the background of a div, but it seems to have vanished! I would like the background image to cover the entire page. Thank you for your assistance. <!DOCTYPE html> <html> <head> <title></title& ...

Is there a way to verify and send notifications when duplicate entries are added to my table?

Whenever a make and model are added using the "add" button, I need to ensure that there are no duplicates. If a duplicate is found, an alert should be displayed, and the entry should not be added to the table. Unfortunately, I have been unable to find a so ...

How to save HTML content in a variable for future use in Next.js

When working with Next JS, my code resembles something like this: function Test() { return ( <section> <div>Test</div> </section> ); } Now, imagine that I want to have multiple entries here, gen ...

Troubles with CSS in MUI Component Integration

How can I successfully implement a vertical timeline using Material UI in React? I've set it up, but the CSS isn't functioning as expected. Is there an error in my implementation? List of Dependencies: "@emotion/react": "^11.11.1& ...

Javascript Calculator with Dual Input Fields

I have been given a task to create a calculator by tomorrow using Javascript. Unfortunately, I am currently taking a distance course and Javascript has just been introduced in this assignment. While I am familiar with HTML and CSS, Javascript is something ...

Tips on validating individual array elements in Laravel

I'm working with an array of indexes that stores data retrieved through an AJAX call. My goal is to implement validation on only one specific index within the array. Here is the relevant section of my code: foreach($request->info as $info){ ...

What is the best way to incorporate a solid element onto a see-through background?

I have a link at "http://hastebin.com/julayefoto.xml" and I need assistance in making the content inside the bubble named "Test Test Test" non-transparent while keeping the bubble itself transparent. Any help would be greatly appreciated. Thank you :) ...