Content does not become interactive upon the initial loading of the page

I've modified a W3 schools slideshow template to use text instead of dots, but I'm encountering two issues

1: The first image doesn't load when the page loads. Although using a class ID and setting it to active fixes this issue, it leads to my second problem.

2: When I force the image to load, the text/button for that first slide is not in an active state. The color should be red for active/hover and grey for inactive, yet when the forced image loads, the text remains grey.

Here's the code snippet:

<style>
{box-sizing: border-box}
.mySlides {display: none}
img {vertical-align: middle;}

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

/* Dots/bullets/indicators style */
.dot {
  cursor: pointer;
  height: auto;
  width: auto;
  margin: 0 2px;
  color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: color 0.6s ease;
}

.active, .dot:hover {
  color: #cc3333;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

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

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

/* Decrease text size on smaller screens */
@media only screen and (max-width: 300px) {
  .prev, .next,.text {font-size: 11px}
}
</style>

<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";  
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
}
</script>

    <div style="border-top: 6px solid #cc3333;padding-bottom: 100px; padding-top: 100px" class="row highlight-phone">
        <div class="container">
            <div class="vidrow">
                <div class="vidcolumn slideshow-container">
                    <div id="slide1" class="mySlides">
                        <img src="https://www.w3schools.com/howto/img_nature_wide.jpg" style="width:100%">
                    </div>
                    <div class="mySlides">
                        <img src="img_snow_wide.jpg" style="width:100%">
                    </div>
                    <div class="mySlides">
                        <img src="img_mountains_wide.jpg" style="width:100%">
                    </div>
                </div>
                <div class="vidcolumn">
                    <div class="intro">
                        <h2 style="text-decoration:overline;text-decoration-color: #cc3333;">How It Works</h2>
                        <div id="dot" class="dot" onclick="currentSlide(1)">Learning Paths</div>
                        <br>
                        <span id="dot" class="dot" onclick="currentSlide(2)">Songs</span>
                        <br>
                        <span id="dot" class="dot" onclick="currentSlide(3)">Training</span>
                        <br>
                        <br>
                        <br>
                        <a class="btn btn-primary btn-lg btn-wi-red btn-pill" role="button" href="#">VIEW DEMO</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

For visual reference, check out the image: Imgur

Any tips on resolving this?

Answer №1

Let's clarify one thing - javascript is not java :). The issue at hand isn't with your javascript code, but rather with the image sources you are using. One of them has a URL while the other two only have local image paths. This discrepancy in image locations is causing the problem. Here are some ways to fix this:

  1. Update the paths to the correct ones in your local directory.
  2. Convert all images to URLs like the first one.

For instance, consider implementing it this way:

 var slideIndex = 1;
  showSlides(slideIndex);

  function plusSlides(n) {
    showSlides(slideIndex += n);
  }

  function currentSlide(n) {
    showSlides(slideIndex = n);
  }

  function showSlides(n) {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    if (n > slides.length) {
      slideIndex = 1
    }
    if (n < 1) {
      slideIndex = slides.length
    }
    for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
    }
    for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
    }
    slides[slideIndex - 1].style.display = "block";
    dots[slideIndex - 1].className += " active";
  }
 *{
    box-sizing: border-box
  }

  .mySlides {
    display: none
  }

  img {
    vertical-align: middle;
  }

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

  /* The dots/bullets/indicators */
  .dot {
    cursor: pointer;
    height: auto;
    width: auto;
    margin: 0 2px;
    color: #bbb;
    border-radius: 50%;
    display: inline-block;
    transition: color 0.6s ease;
  }

  .active,
  .dot:hover {
    color: #cc3333;
  }

  /* Fading animation */
  .fade {
    -webkit-animation-name: fade;
    -webkit-animation-duration: 1.5s;
    animation-name: fade;
    animation-duration: 1.5s;
  }

  @-webkit-keyframes fade {
    from {
      opacity: .4
    }

    to {
      opacity: 1
    }
  }

  @keyframes fade {
    from {
      opacity: .4
    }

    to {
      opacity: 1
    }
  }

  /* On smaller screens, decrease text size */
  @media only screen and (max-width: 300px) {

    .prev,
    .next,
    .text {
      font-size: 11px
    }
  }
<div style="border-top: 6px solid #cc3333;padding-bottom: 100px; padding-top: 100px" class="row highlight-phone">
  <div class="container">
    <div class="vidrow">
      <div class="vidcolumn slideshow-container">
        <div id="slide1" class="mySlides">
          <img src="https://www.w3schools.com/howto/img_nature_wide.jpg" style="width:100%">
        </div>
        <div class="mySlides">
          <img src="https://www.w3schools.com/howto/img_snow_wide.jpg" style="width:100%">
        </div>
        <div class="mySlides">
          <img src="https://www.w3schools.com/howto/img_mountains_wide.jpg" style="width:100%">
        </div>
      </div>
      <div class="vidcolumn">
        <div class="intro">
          <h2 style="text-decoration:overline;text-decoration-color: #cc3333;">How It Works</h2>
          <div id="dot" class="dot" onclick="currentSlide(1)">Learning Paths</div>
          <br>
          <span id="dot" class="dot" onclick="currentSlide(2)">Songs</span>
          <br>
          <span id="dot" class="dot" onclick="currentSlide(3)">Training</span>
          <br>
          <br>
          <br>
          <a class="btn btn-primary btn-lg btn-wi-red btn-pill" role="button" href="#">VIEW DEMO</a>
        </div>
      </div>
    </div>
  </div>
</div>

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

Using the hash(#) symbol in Vue 3 for routing

Even though I am using createWebHistory, my URL still contains a hash symbol like localhost/#/projects. Am I overlooking something in my code? How can I get rid of the # symbol? router const routes: Array<RouteRecordRaw> = [ { path: " ...

Error in CSS Header - Position Shifts when Hovered Over

UPDATED HEADER HTML/CSS I am currently working on the header section of my website at . I encountered a bug where, upon hovering over the links in the header from right to left, the positions of the links become disorganized. I am unsure of what might be ...

Generating and Importing Graphics through Iterations in Javascript

I apologize for my lack of experience in this matter. Can someone please guide me on how to utilize a loop to load images? For instance, could you show me how to rewrite the code below using a loop to automate the process? function loadImages() { let ...

Locating the xpath of an element directly beneath the opening <body> tag

I'm having trouble finding the xpath for an element that is not associated with any html tags. Please see the attached image for reference. I tried using driver.findElement(By.xpath("/html/body/"));, but it's not working. I need to locate the tex ...

Calculate the total number of blank input boxes within a specific row of the table

What is the method to count the number of input boxes without a value in a table row using jquery? For instance: <table id="table1"> <tr class="data" id="row5"> <td><input type="text" value="20%" /></td> <td><input ...

Implement Infinite Scrolling Pagination in WordPress

I'm completely new to Wordpress and currently utilizing the FoundationPress theme. My goal is to include a button that users can click on to load more posts. Essentially, I want users to see four blog posts initially and then be able to load the next ...

Displaying the structure of a MongoDB database using Express and Angular in a tabular format

I am looking to present the data from MongoDB in a table format using HTML along with Node.js, Express.js, and Angular.js. Currently, my approach is as follows: route.js app.get('/superhero', function(req, res) { superhero.superhero_list(r ...

Why does the node.js app only run from the command prompt and not directly?

I have a basic vbscript that launches two nodejs apps necessary for my server's operations. Dim objShell Set objShell = Wscript.CreateObject("WScript.Shell") objShell.Run "node C:\!webroot\site.name\server\pubsub.js" objShell.Run ...

How can I simulate keyboard events in Angular using a button click?

I've included separate buttons for Ctrl+z and Ctrl+y functionalities. When these buttons are clicked, I want them to perform the respective undo and redo actions programmatically. Below is the code snippet for this functionality. undoText(event:MouseE ...

Tips for organizing and sorting date data in a JSON datatable

I am working with two date input fields: <form id="refresh" method="post" action="income.php"> <input type="text" id="dari" name="dari" /> <input type="text" id="sampai" name="sampai" /> <button type="submit">Refresh</b ...

The width of Bootstrap 5.3.0 form checkboxes varies between options

CSS input[type='checkbox'] { transform: scale( 2 ); margin-right: 1.5em; } Html <div class="form-check d-flex align-items-center mb-3"> <input class="form-check-input" type="checkbox" value=&quo ...

Having trouble getting items to align properly in Bootstrap

As a student, I am struggling with my development skills while attempting to create a personal website. I am encountering difficulty aligning items on my rows in bootstrap. Here is what I am trying to accomplish: 1. However, I am currently stuck at this po ...

LESS: Using variable values in mixin and variable names

I am looking to simplify the process of generating icons from svg-files while also creating a png-sprite fallback for IE8 support. I am using grunt.js and less. I was inspired by the implementation on 2gis.ru: (in Russian), where they used technologies s ...

Can you identify the nature of the argument(s) used in a styled-component?

Utilizing typescript and react in this scenario. Fetching my variable const style = 'display: inline-block;' Constructing a simple component export const GitHubIcon = () => <i className="fa-brands fa-github"></i> Enh ...

An easy CSS conundrum when hovering

Looking for some assistance with CSS. I want to display the text "Featured Page" with a picture appearing on the right side upon hovering (mouseover). Currently, the picture shows up under the text using the following CSS, but I need it to be larger and pl ...

I successfully developed a unique custom accordion feature in React.js, where the toggle functionality is fully functional. However, I am currently facing an

import React, { useState, useEffect } from "react"; import axios from "axios"; const Faq = () => { const [faq, setFaq] = useState([]); const [activeIndex, setActiveIndex] = useState(null); const fetchFaqs = async () => { ...

The navigation bar in Bootstrap 3.2 expands in size as you scroll past it

Whenever I reach the bottom of the page, the navigation bar suddenly enlarges. The navbar is located at the top of my code. I attempted moving the navigation to the bottom of the code... but it didn't fix the issue... Could someone please identify wha ...

Interacting with wpdb using AngularJS

I just started learning AngularJS and I'm eager to implement it on my WordPress website. My goal is to display a table with data from a database in my WordPress site, but I am encountering difficulties accessing the WordPress functions and variables. ...

Arrange divs in a grid layout with evenly distributed dynamic spacing

I am not a big fan of bootstrap, so I was wondering if it is possible to achieve the layout without using it. I have 6 divs that I want to arrange in 2 rows and 3 columns. I need the space between each row/column to be precise. While I can calculate this ...

What are the steps for integrating mongoDB with an angular2 application?

I currently have my angular2 & mongoDB setup successfully. While I've managed to read JSON files using the HTTP service, my goal is to create a fully functional application with database connectivity as well. I'm seeking advice on how to con ...