What is the best way to implement next and previous buttons in a slideshow using code?

Looking to enhance my slideshow by replacing the standard "Next" and "Previous" text buttons with custom JPEG images I've created. Anyone familiar with the steps needed to make this switch in the HTML code?

Current HTML code in use:

    <body style="font-family: Arial, Sans-serif, sans;">

    <h2>Top 10 Vehicles Among US-Hispanics</h2><br />


    <div id="slideshow">
<div class="sp">
    <img src="img/banner01.jpg" alt="Toyota Corolla" /></a>
    <br><strong>1. Toyota Corolla</strong><br>
    The 2013 Toyota Corolla is a study in practicality and stylish engineering. The Corolla starts at $16,800 for the basic L model and comes with eight airbags, power windows and door locks, LED headlamps and running lights, Bluetooth connectivity, and a USB port. The comparatively deluxe S model ($19,000) comes with integrated spoiler and fog lamps, a leather-wrapped steering wheel, chrome-tipped exhaust and a 3.5-inch multi-information display. The Corolla offers an estimated 28/37 mpg.
</div>

<div>
    <img src="img/banner02.jpg" alt="Honda Civic" /></a>
    <br><strong>2. Honda Civic</strong><br>
    The Honda Civic, a longtime favorite sedan among fuel-conscious drivers, comes in six models, including hybrid and natural gas versions.  The 4-door access and roomy interior give the Civic the feel of a much larger sedan, but the 1.8-liter engine offers exceptional fuel economy, rated at 28 city/39 for the LX sedan and 44/44 for the hybrid. The Civic comes with standard front and side airbags, 4-wheel anti-lock disc brakes, a rear-view camera and Bluetooth connectivity. Pricing starts at $18,165 for the LX and ranges up to $24,360 for the hybrid. The basic coupe starts at $17,965.
</div>

<div>
    <img src="img/banner03.jpg" alt="Honda Accord" /></a>
    <br /><strong>3. Honda Accord</strong><br>
    The 2013 Honda Accord proved to be popular with drivers and professional reviewers alike. The new direct-injection 4-cylinder engine with continuously variable automatic transmission delivers smooth acceleration and nice mileage numbers, beginning at an affordable MSRP of $21,680 for the basic model, on up to $33,430 with the bells and whistles. A V6, 6-speed manual and 6-speed automatic are also available. Mileage ranges from 21/32 for the EX-L V6 Automatic Coupe with Navigation to 27/36 for the 4-cylinder CVT.
</div>

... (additional vehicle descriptions omitted for brevity) ...

    </div>


     <div id="nav"></div>
            <div id="button-previous">prev</div>
        <div id="button-next">next</div>

Current CSS code:

    <style type="text/css">

    /*** set the width and height to match your images **/

    #slideshow {
position:relative;
height:560px;
width:620px;
    }

    #slideshow DIV {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
height: 560px;
width:620px;
background-color: #FFF;
    }

    #slideshow DIV.active {
z-index:10;
opacity:1.0;
    }

    #slideshow DIV.last-active {
z-index:9;
    }

    #slideshow DIV IMG {
height: 350px;
display: block;
border: 0;
margin-bottom: 10px;
    }

    #nav {margin-top:10px; width:100%;}
    #button-previous {
float:left;margin-left:200px;
cursor:pointer;
}
    #button-next {
float:right;margin-right:200px;
cursor:pointer;
}

Current jQuery code:

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

    <script type="text/javascript">


    $(document).ready(function(){
    $('.sp').first().addClass('active');
    $('.sp').hide();    
    $('.active').show();

$('#button-next').click(function(){

$('.active').removeClass('active').addClass('oldActive');    
               if ( $('.oldActive').is(':last-child')) {
    $('.sp').first().addClass('active');
    }
    else{
    $('.oldActive').next().addClass('active');
    }
$('.oldActive').removeClass('oldActive');
$('.sp').fadeOut();
$('.active').fadeIn();


});

   $('#button-previous').click(function(){
$('.active').removeClass('active').addClass('oldActive');    
       if ( $('.oldActive').is(':first-child')) {
    $('.sp').last().addClass('active');
    }
       else{
$('.oldActive').prev().addClass('active');
       }
$('.oldActive').removeClass('oldActive');
$('.sp').fadeOut();
$('.active').fadeIn();
});




    });



    </style>

Thank you, Ron

Answer №1

Experiment with this CSS suggestion:

#previous-button{color:transparent; background:transparent url(your_next_image.png) no-repeat 50%}
#next-button{color:transparent; background:transparent url(your_previous_image.png) no-repeat 50%}

Just like that!

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

Enhancing User Interaction: Tips for Focusing on Touch in React Input Text Field

Having a bit of an issue with my input component that works perfectly on desktop but seems to be malfunctioning on mobile. I can't seem to get it to focus on press, and all the solutions I'm finding are related to React Native which I'm not ...

Bootstrap 5's ScrollSpy functionality seems to be malfunctioning

I attempted to implement the scroll-spy feature of Bootstrap 5 in order to highlight the corresponding navbar item as active while scrolling through different sections of my HTML page. However, I encountered an issue where the navigation-link item would be ...

Dynamic rows in an Angular 2 Material data table

I'm currently working on dynamically adding rows to an Angular 2 Data Table ( https://material.angular.io/components/table/overview) by utilizing a service called "ListService". This service provides me with the columns ("meta.attributes") to be displ ...

Is it possible to eliminate the table borders and incorporate different colors for every other row?

Eliminating the table borders and applying color to alternate rows. Check out my code snippet: https://stackblitz.com/angular/dnbermjydavk?file=app%2Ftable-overview-example.ts. ...

What is the correlation between statistics and posts that are generated dynamically?

One interesting aspect to consider is how statistics are connected to individual posts. For instance, linking the like count to each Facebook post or tying upvote and downvote stats to a question on Stackoverflow presents some intriguing challenges. How ...

I possess a primary menu with several submenus, yet I am encountering difficulty accessing the submenus. My goal is to efficiently navigate and access the appropriate submenu within the main menu

I am facing an issue with my CSS where the sub menu is currently showing from the left side, but I would like it to slide up and down instead. .outer { width: 100%; text-align: center; background-color: Gray; padding-top: 20px; bord ...

What is the best way to reset an angularJS form after it has been submitted

I am trying to figure out a way to clear form fields on a modal window after the user executes the save method. I have attempted using $setPristine in AngularJS, but it's not working as expected. Any suggestions on how to achieve this task? Here is t ...

Empty Data Returned After Sending AJAX Request

Currently, I am delving into the world of ajax in order to simplify my life going forward. I successfully managed to implement an example where a constant array was posted to my controller without any issues. However, when attempting to fetch data from an ...

Troubleshooting: Issue with append function not functioning properly after click event in Angular

I am struggling to implement a basic tooltip in AngularJS. Below is the HTML I have: <span class="afterme" ng-mouseover="showToolTip('this is something', $event)" ng-mouseleave="hideToolTip();"> <i class="glyphicon glyphicon-exclama ...

Tips for selecting the correct date on a DatePicker using selenium?

I am facing an issue with my selenium test related to a date picker on a webpage. The task is to select a specific date (e.g., 14/2/2012) by clicking on the correct day. However, the date picker is generated using jQuery as shown in the code snippet belo ...

Having trouble parsing the JSON object values within the Error section of the Ajax call

When making an Ajax call to a rest web API, I encountered an error that I need help resolving. Here is the code snippet: $.ajax({ url: "/********/getbytitle('****')/items", type: "POST", contentType: "applicat ...

Even though the onSubmit attribute is set to false in the HTML form, it still submits

I've been struggling with a form that just won't stop submitting, no matter what I do. I have checked similar questions on SO, but none of the solutions seem to work for me. It's frustrating because it's such a simple task. The reason w ...

Discover Vuejs: Display Less, Reveal More

In order to achieve a specific task, I need to display 12 items in 4 columns with 4 items each. Initially, only the first four items are visible and the rest are hidden until the user clicks the "Show More" button. Upon clicking the button, the next row ...

What is the best way to reverse a condition in CSS?

Here is my HTML/CSS code, I am relatively new to this field. Please let me know if I have overlooked anything. .dropdown-menu>li>a { padding: 3px 5px; } <li> <a id="btn-other-1" href="#"> <!–- I do not want apply css for t ...

The CSS class is not properly implemented in the React component

I value your time and assistance. I have spent many hours trying to solve this issue but seem unable to reach a resolution. Here is the React component in question: import styles from './style.scss'; class ButtonComponent extends React.Compone ...

Ensuring Compatibility of jQuery with Internet Explorer

Attempting to display a long and intricate source code, I have decided to share a link to the problematic page instead. In Google Chrome or newer Firefox versions (5 or 6), the jQuery in this script functions as intended. However, issues have arisen in IE ...

Using Javascript's OnChange event to dynamically update data

Attempting to achieve a seemingly straightforward task, but encountering obstacles. The goal is to trigger a JavaScript onChange command and instantly update a radar chart when a numerical value in a form is altered. While the initial values are successful ...

Vue.Js allows developers to easily set a default selected value in a select dropdown menu

Having trouble with getting the default selected value using select in VueJs. I've attempted two different approaches: Using id and v-model fields in the select like this: <select v-model="sort_brand" id="sort-brand" class="form-control"> ...

Bootstrap version 5.3.0 has a unique behavior where dropdowns placed outside the collapsed area of the navbar will display the menu inside the navbar, rather than outside

Is there a way to fix the issue where the dropdown menu appears in the body of the navbar when it is collapsed? I have tried using attributes like data-bs-reference but couldn't find much information on how to resolve this. <nav class="navbar ...

Connect the checkbox input to the text input

I'm facing an issue where I need to tie a checkbox input to a text input in my form. Here's the scenario: I am extracting data from a database. The primary key data serves as the value for the checkboxes. When a checkbox is selected, it should ...