My presentations are not functioning as expected, could there be a problem with my HTML, CSS, or JavaScript coding?

My website utilizes a Slideshow feature to display images for blog posts. Recently, I attempted to include multiple slideshows within an article, which unfortunately caused all of the slideshows to malfunction. As it stands now, when the code is executed, none of the images are displayed on the screen. Only the navigation arrows appear, but clicking on them does not have any effect. Below, you can find the HTML, CSS, and JavaScript code used for this functionality. I would greatly appreciate it if someone could help me resolve this issue.

HTML:

<div class="mySlides1">
   <div class="numbertext">1 / 2</div>
   <img class="the-article-imgs-vert" src="/images/2022/04/image.jpg" style="width:100%">
    <div class="the-article-imgs-caption">Text here</div>
</div>

<div class="mySlides1">
    <div class="numbertext">2 / 2</div>
    <img class="the-article-imgs" src="/images/2022/04/image-2.jpg" style="width:100%">
    <div class="the-article-imgs-caption">Text here</div>
</div>

<a class="prev" onclick="plusSlides(-1, 0)">&#10094;❮</a>
<a class="next" onclick="plusSlides(1, 0)">&#10095;❯</a>

<div class="mySlides2">
    <div class="numbertext">1 / 2</div>
    <img src="/images/2022/04/photo_2022-04-02_19-33-27.jpg" style="width:100%">
    <div class="the-article-imgs-caption">caption here</div>
</div>

<div class="mySlides2">
    <div class="numbertext">2 / 2</div>
    <img src="/images/2022/04/photo_2022-04-02_19-33-18.jpg" style="width:100%">
    <div class="the-article-imgs-caption">caption .</div>
</div>

<a class="prev" onclick="plusSlides(-1, 1)">&#10094;❮</a>
<a class="next" onclick="plusSlides(1, 1)">&#10095;❯</a>

CSS:

    /* Article Image */

.the-article-imgs {
  height: 100%;
  max-width: 990px;
  min-width: 100%;
  width: 100%;
}

.the-article-imgs-caption {
  text-align: center;
}

.the-article-imgs-vert {
  height: 45%;
  max-width: 456px;
  min-width: 54%;
  width: 100%;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* Slideshow Image Code */

* {box-sizing: border-box}

.mySlides, .mySlides1, .mySlides2, mySlides3, .mySlides4, .mySlides5, .mySlides6:first-of-type, {display: block;}

.mySlides, .mySlides1, .mySlides2, mySlides3, .mySlides4, .mySlides5, .mySlides6 {display: none;}

.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  color: blue;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
}

.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: #717171;
}

.fade {
  animation-name: fade;
  animation-duration: 1.5s;
}

@keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

@media only screen and (max-width: 300px) {
  .prev, .next,.text {font-size: 11px}
}

Javascript:

let slideIndex = [1,1];
let slideId = ["mySlides1", "mySlides2"]
showSlides(1, 0);
showSlides(1, 1);

function plusSlides(n, no) {
  showSlides(slideIndex[no] += n, no);
}

function showSlides(n, no) {
  let i;
  let x = document.getElementsByClassName(slideId[no]);
  if (n > x.length) {slideIndex[no] = 1}    
  if (n < 1) {slideIndex[no] = x.length}
  for (i = 0; i < x.length; i++) {
     x[i].style.display = "none";  
  }
  x[slideIndex[no]-1].style.display = "block";  
}

Answer №1

To optimize loading time, I recommend downloading the script concurrently with parsing the page. Make sure to include the async attribute when referring to your JavaScript file like this:

<script src="index.js" async></script>

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 it unwise to conceal the horizontal scrollbar?

My webpage includes a jquery slideshow using the jquery circle plugin, featuring the "shuffle" option. var slideshow = $('#slider').cycle({ fx: 'shuffle', shuffle: { top: 0, left: 1300}, .... When the images move out ...

Having difficulty transmitting the value attribute to the server via ajax

$(function(){ $('.menu').on('click', (function(){ $('#box').toggle('slide'); $.ajax({ url:'fetchsubmenu.php'; data : {nume : $(this).attr('value')}, dataType : ...

"What is the best way to transform tab navigation into a dropdown menu with the help

I have a collection of tabs currently on display. I am looking to transform them into a dropdown menu when the screen size changes, making them more responsive. Each set of tabs corresponds to different content. Despite trying various solutions found on s ...

Guide on updating data within a file at a specific position using JavaScript

I am faced with a challenge involving a file containing the following data, Test.txt, <template class="get" type="amp-mustache"> <div class="divcenter"> /////Need to append data at this point///// </div> </template> ...

What steps should I take to resolve npm start issues within my Node.js application?

Upon completing the npm install, I attempted to run npm start for my project. Unfortunately, an error was displayed. What steps can be taken to resolve this issue?view image of the error here ...

Ways to prevent a floated element from impacting text-align: center styling?

Within my code, there is a <p> element structured as follows: <div><p>Text Goes Here <span></span</p></div> The CSS I currently have is: div { text-align:center } span { float:right } An issue arises when I populate ...

JavaScript: Learn how to simultaneously open two links from the current webpage

I am trying to create a browser bookmark that will open a link with the id: window.getElementById('updateOk').click() followed by opening a small window with another button: document.getElementsByClassName('rmit-save-details btn btn-inlin ...

Embed one module within another module and utilize the controller from the embedded module

I am attempting to create a module and inject it into the main module. Then, I want to inject the controller into the injected module but am facing issues. In my index.html file: <html ng-app="MenuApp"> <head> </head> <body> <d ...

Alter the command from 'require' to an 'import'

Utilizing https://www.npmjs.com/package/json-bigint with native BigInt functionality has been a challenge. In the CommonJS environment, the following code is typically used: var JSONbigNative = require('json-bigint')({ useNativeBigInt: true }); ...

Fetching images using node.js via URL

I must apologize for my lack of knowledge about node.js. I am trying to read an image from a URL and resize it using sharp. Currently, my code only works for reading local images. For instance, I would like to read the following image from a URL: url= ...

Utilize ajax requests to dynamically enable or disable input fields

Currently, I am developing an attendance management system for employees. The attachment below contains three input fields - one dropdown and two calendar fields. The dropdown includes the names of employees, the second field displays the current date and ...

Loading Jquery Image Swapping

Is there a simpler way to change the src attribute of a group of images to match their respective title attributes? <img src="" title="images/1.png" class="images" /> <img src="" title="images/2.png" class="images" /> <img src=" ...

Looping in jQuery: Tips for Improving Performance

In my popup window, I have a JavaScript function that utilizes jQuery to retrieve checked checkboxes from the parent window. It then uses jQuery again to access associated data from hidden fields in the parent window for each checkbox. var chked = $(&apos ...

Switching the visibility of multiple textareas from block to none

I am currently exploring ways to make one text area disappear while another one appears in its place. With limited knowledge of Javascript and just starting my journey into HTML and CSS, I am reaching out to the forum for assistance or guidance on the rig ...

What is the best way to restore a component's state to its default settings when it receives new props?

I have a Next.js project in development with a custom Layout already set up. I want the header component to reset whenever a new page is navigated to, so that the menu reverts back to its default state. Does anyone know how I can achieve this? import { F ...

What is the purpose of returning a function in a React Hook?

Currently, I am incorporating Material-UI components into my project and have implemented the AutoComplete component in my application. While exploring an example provided by the Material-UI team, I stumbled upon a fascinating instance of using Ajax data ...

A more efficient method for refreshing Discord Message Embeds using a MessageComponentInteraction collector to streamline updates

Currently, I am working on developing a horse race command for my discord bot using TypeScript. The code is functioning properly; however, there is an issue with updating an embed that displays the race and the participants. To ensure the update works co ...

Having trouble with asynchronous JSON calls in JavaScript when setting async to false

I'm having trouble figuring out what I'm doing wrong in this scenario. The issue is that I can't seem to reassign the variable poster_path with the fetched poster-path from the JSON call. What's puzzling to me is that I even tried setti ...

Exploring ways to display all filtered chips in Angular

As a new developer working on an existing codebase, my current task involves displaying all the chips inside a card when a specific chip is selected from the Chip List. However, I'm struggling to modify the code to achieve this functionality. Any help ...

Utilize a viewpoint alteration alongside a floating effect on a specific element

I thought this would be an easy task, but I seem to be missing something as it doesn't work for me. The goal is to use the perspective() and rotateY() functions in a transform to create a perspective effect on an element. Additionally, there should b ...