Incorporating Next and Previous navigation buttons to my slideshow

I'm looking to enhance my image slider by including next and previous buttons, but I'm unsure of how to proceed. Can anyone provide guidance or assistance with this? Below is the basic structure that I currently have in place:

Here is the code snippet:

HTML

<div class="large-photo">
    <img src="images/large-photo/photo1.jpg" class="active">
    <img src="images/large-photo/photo2.jpg">
</div>
<div class="small-photo">
    <img src="images/small-photo/photo1.jpg" class="thumb selected">
    <img src="images/small-photo/photo2.jpg" class="thumb">
</div>
<div class="arrow">
    <div class="left-arrow"></div>
    <div class="right-arrow"></div>
</div>

CSS

.large-photo img {
    display: none;
}
.large-photo img.active  {
    display:block;
}
.small-photo img.selected {
    border: 3px solid red;
}

JAVASCRIPT

function loadPhoto() {
    $('.small-photo img').click(function() {
        $('.selected').removeClass('selected');
        var index = $(this).index();
        $('.large-photo img.active').removeClass('active');
        $('.large-photo img').eq(index).addClass('active');
        $(this).addClass('selected');
    });
}

Answer №1

Understanding your requirements based on the code provided was a bit challenging for me at first, but you will soon grasp how this system functions and how to customize it as needed. CODE:

<script type="text/javascript" src="jquery-2.js"></script>
<script type="text/javascript">

    $(document).ready(function(){
        $("#left-arrow").click(function(){

            $(".small-photo").fadeIn();
            $(".large-photo").fadeOut();
        });

        $("#right-arrow").click(function(){
            $(".small-photo").fadeOut();
            $(".large-photo").fadeIn(1000);
        });
    });


</script> 

<div id="container">
<div class="large-photo">
         <img src="images/updated_large_image_1.png">
         <img src="images/updated_large_image_2.png">
     </div>
     <div class="small-photo">
         <img src="images/updated_small_image_1.png" >
         <img src="images/updated_small_image_2.png" >
     </div>

    </div>
     <div class="arrow">
          <a href="#" id="left-arrow">&lt;-</a> 
          <a href="#" id="right-arrow">-></a> 
      </div> 

Some major changes had to be made, such as removing CSS for demonstration purposes. Feel free to add back any styles as required. I also replaced some classes with ids and changed the images - make sure to update them with your own images.

See the demo in action.

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

Tips for optimizing AJAX content for Google indexing

As I begin the process of developing a public website that utilizes client-side rendering with AngularJS, I have come across information suggesting that dynamically generated content may not be properly indexed by Google. This raises concerns about the imp ...

Utilizing HTML5 to automatically refresh the page upon a change in geolocation

I have a web application built with AngularJS. One of the functionalities is activated only when the user is in close proximity to specific locations. To make this work, I can constantly refresh the page every 5 seconds and carry out calculations to dete ...

React.js - Using functions as a React child is not allowed

I recently started learning React.js but I'm stuck on a problem. I keep receiving this warning message: Functions aren't valid as a React child. This might be due to returning a Component instead of from render. Or maybe you intended to call this ...

Enhance your web form with the Bootstrap 4 tags input feature that allows users to add tags exclusively

I'm currently utilizing Bootstrap 4 along with Bootstrap Tags Input to create a multiple category selection feature. My goal is to enable users to choose multiple items exclusively from the predefined categories listed in the predefined_list. At pres ...

Shifting components around with CSS

My website's home page appears differently on a 1920px screen (big desktop screen) versus a 1366px (15" laptop) screen. While it looks perfect on the larger screen, there is a noticeable gap between the menu, text below, and the banner image on the s ...

In Javascript, the DOM contains multiple <li> elements, each of which is associated with a form. These forms need to be submitted using AJAX for efficient

I have a list element (ul) that includes multiple list items (li), and each list item contains a form with an input type of file. How can I submit each form on the change event of the file selection? Below is the HTML code snippet: <ul> ...

How can I transfer information from an HTML file (using the ejs template engine) to Node.js?

Currently, I am working on my own project using a combination of Node.Js (Express), MongoDB, JavaScript/jQuery, and HTML with EJS as the template engine. So far, I have some understanding of how to send data from the Node.js router to views and how to sen ...

The addEventListener feature in Bootstrap 5.2.3 seems to be malfunctioning

I have a sample page with a Bootstrap dialog being returned from the server. I want to display it inside a DIV. However, when clicked, I receive this error: Uncaught TypeError: myModal.addEventListener is not a function It points to this line of code: ...

The HTML password input continues to respond to key bindings, even when other inputs are not affected by the bindings

In the ongoing development of a legacy react application, I encountered keybindings that are causing unexpected behavior. For instance, pressing the "F" key triggers the full screen mode within the app. However, this keybinding is inadvertently active for ...

Position the Crossmark to align with text using CSS styling

How can I properly align a crossmark and a checkmark with the text behind them? The checkmark looks aligned well, but the crossmark appears to be slightly off to the top-right. I'm hesitant to adjust margins and paddings as it may cause issues when th ...

What is the best way to retrieve a specific property or attribute of a specific div element after obtaining it from e.target.parentNode?

e.target.parentNode will return this element. <div class="quantity"> <span class="glyphicon glyphicon-minus-sign"></span> <span class="product_Count"> 4 </span> <spa ...

The disappearance of the tooltip arrow is triggered by the presence of overflow-y: auto in

My issue involves a tooltip that utilizes a span element to load content. This content can vary in size, so I have set maximum height and width values on the span. My intention is for the content to scroll when it exceeds these dimensions. The problem ari ...

Is there a way to ensure that res.render() is only triggered after the steps mentioned above have been completed?

My goal is to ensure that the completion of the for loop happens before the execution of the res.render() function synchronously. Currently, the res.render() function is running before the for loop is completed. I have tried using a setTimeout function t ...

The attribute 'checked' is not a valid property for the 'TElement' type

Learning about typescript is new to me. I have a functional prototype in fiddle, where there are no errors if I use this code. http://jsfiddle.net/61ufvtpj/2/ But in typescript, when I utilize this line - if(this.checked){ it presents an error [ts] Pro ...

How can I make a checkbox checked in AngularJS?

Hello, I am currently working on a web application using AngularJS. Within this application, I have a form where I am populating values into a multi-select dropdown. <li ng-repeat="p in locations"> <input type="checkbox" ng-checked="master" n ...

What could be causing the absence of HTML attribute suggestions in my Visual Studio Code?

I'm experiencing an issue in my VS Code where the suggestion feature is not working properly. When I try to type "onClick, href, src, etc", the suggestions do not show up as they should. Interestingly, this problem doesn't occur in my older code ...

Struggling to Add JetBrains IDE Support to Chrome

Struggling with setting up JetBrains IDE Support for Chrome. The browser keeps saying: This application is not compatible with your device. Installation has been disabled. Any solutions to this issue? Thanks, Alex ...

"Exploring the concept of odd and even numbers within the ng-repeat

Can anyone help me with detecting odd or even numbers in an ng-repeat? I have created a fiddle that displays some dots randomly showing and hiding. Now, I want to change the background color so that odd numbers are green and even numbers are red. function ...

The jQuery plugin is not functioning properly on the subdomain

Encountered an issue where a jQuery plugin is not loading in Chromium for a peculiar reason. Interestingly, the plugin loads fine when accessing the page through the root domain but fails to load when accessed via a subdomain in Chromium. However, everyth ...

How can I refresh a Vue.js component when a prop changes?

Initially, I utilize a random number generator to create numbers that will be used in my api call created() { for (let i = 0; i < this.cellNumber; i++) { this.rng.push(Math.floor(Math.random() * 671 + 1)); } These generated numbers are stored in an a ...