What is the reason for the incompatibility between Bootstrap and Vanilla JavaScript?

Why does my slideshow crash when I use Bootstrap with vanilla JavaScript? It seems like there is a timeout or something...

I'm not sure why this is happening. When I remove Bootstrap, the slideshow works fine. Here is my code:

I attempted to remove Bootstrap and the slider is working without any issues. However, I want to use Bootstrap. Is there a solution? Here is my code:

HTML:

<!DOCTYPE html>
    <html lang="en" dir="ltr">
    <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <header class="header">
      <div class="logo-box">
        <img src="images/logo.png" class="logo" alt="">
      </div>
      <nav class="navbar navbar-expand-lg ">
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="">Reservation</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Menu</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Our Chefs</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Events</a>
            </li>
        </ul>
    </nav>
    </header>
    <div class="slideshow-container">
      <div class="mySlides fade">
        <img src="images/food3.png" class="img">
      </div>
      <div class="mySlides fade">
        <img src="images/pizza.png" class="img" >
      </div>
      <div class="mySlides fade">
        <img src="images/hamburger2.png" class="img" >
      </div>
    
      <div class="dotz">
        <span class="dot" onclick="currentSlide(1)"></span>
        <span class="dot" onclick="currentSlide(2)"></span>
        <span class="dot" onclick="currentSlide(3)"></span>
      </div>
      <script src="script.js" charset="utf-8"></script>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
  </body>
</html>

CSS:

* {box-sizing:border-box;
margin:0;}
.img{
  width: 100%;
  user-select: none;
}
.slideshow-container{
  max-width: 93rem;
  position: relative;
  margin: auto;
}
 .dot {
   position: relative;
   top: -30px;
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 20px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}
.active{
  background-color: #ff9900;
}
.dot:hover {
  background-color: #ff9900;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}
.dotz{
  text-align:center;
}
@keyframes fade {
  from {opacity: .4}
  to {opacity: 1}
}

Javascript

var slideIndex=1;
 showSlides(slideIndex);
 function currentSlide(n){
   showSlides(slideIndex=n);
 }
 function showSlides(n){
   var i;
   var slides=document.getElementsByClassName("mySlides");
   var dots=document.getElementsByClassName("dot");
   for (var i = 0; i < slides.length; i++) {
     slides[i].style.display="none";
   }
   for (var 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";
 }

Answer №1

Consider changing the name of the fade class to a different term (such as js-fade). Bootstrap utilizes the fade class for certain elements (e.g. modal), which could be the reason for the problem you're experiencing.

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

Place a request for the Material UI switch on the platform

I'm currently in the process of constructing a switch that gets its checked value from the data retrieved from the backend. When a user toggles it, a PUT request is sent to the backend for updating the choice. Although I've made progress on it, ...

A guide on using Material UI - InputLabel in JavaScript

I'm currently integrating a form from this Codepen link into my project built with Codeigniter. However, I am encountering issues after incorporating material-ui into the CodeIgniter framework. The problems I am facing include an invalid token and an ...

Unable to fetch the identification number from the database

I'm encountering an issue with retrieving the ID from my database: https://i.sstatic.net/oSAi8.jpg Here is a snapshot of my database: https://i.sstatic.net/j5PpZ.jpg Below is my event controller class: <?php namespace App\Http\Contro ...

JS Data error: The attributes provided must include the property indicated by idAttribute - particularly with regards to hasMany relationships

Encountered Error: The main key for my user model is username. The primary key for my routes is the routename. When my API returns JSONs, they are nested inside data:{} following jsonapi.org specifications. However, this structure differs from what js-dat ...

Altering the context of Javascript script execution

I needed to switch the JavaScript execution context from the parent window to the child window. I was able to successfully load my script objects and functions into the child window context, however, I encountered difficulty in making third party libraries ...

Iterate through all elements in Javascript/jQuery while excluding any nested children elements

Looking to retrieve all elements in the document: $("*").each(function(){ var el = $(this); }); I want to target only parent elements, excluding their children. For example: <div> <!--TARGET--> <div></div> <!--IGNORE--&g ...

Modify the appearance of an element within an array upon selection by comparing it with a separate array

In my code, there is an array called tagList that contains a list of objects. When one of these objects is clicked on, it gets added to another array named selectedTags. var selectedTags = []; export default class RegisterTags extends Component { con ...

How do I modify the date format displayed in the Bootstrap 4 datetimepicker when sending the value?

I have a datetimepicker() set with ID start_date that matches an input name. In the props, the format is specified as YYYY-MM-DD. I want to use this format for my API, but I want the user to see the date displayed in the format DD-MM-YYYY. $('#start_ ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

Confirmation message for deletion using jQuery on dynamic elements

My div is populated with dynamically added records. Whenever I click on the 'Remove' link, a confirmation box pops up multiple times corresponding to the number of records present in the div. I want the confirmation box to appear only for the spe ...

Is it possible to load Javascript using AJAX with jQuery?

So I have this JavaScript code that I insert into a webpage using the following: <script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/sm13154955?w=640&h=395"></script> It basically places an object/embed code into the w ...

Disregard the Field File when utilizing jQuery validation

I have created a form with jQuery validation, but I am facing an issue where the file upload field is showing a message "enter no more than 3 characters." I believe this problem is due to the maxlength="3" property in the file field. How can I remove the ...

Finding the Attachment ID on a JIRA Issue Page with JavaScript

Currently, I am using an ajax call that requires the attachment id in its URL. The URL is hardcoded as follows: url: AJS.contextPath()+"/rest/api/latest/attachment/10415" jQuery.ajax({ url: AJS.contextPath()+"/rest/api/latest/attachment/10415", TYPE: "GET ...

Exploring the possibilities of manipulating the query string with Vue router in vue.js

I've been working on a Vue.js app that includes a tagging feature. I'm looking to implement URL parameters like where users can add tag_ids by interacting with the UI. Although I've successfully managed to update the tag_ids within the app ...

Checking for an active listening instance of `http.Server` in a Node application

Having an http server and a piece of code that needs to run only when the server is actively listening, I have bound it to the event "listening" as follows : server.on('listening', doSomething) The issue arises when the server is already listen ...

Hide the external div if the tab is active in Angular Bootstrap

How can I determine if a specific tab is active and then hide a div outside all tabs when it is active? Plunker: https://plnkr.co/edit/b9O9S7JxxgzhQKcKONkn?p=preview <div class="border"> Conceal me when Tab #3 is active. </div> < ...

AngularJS is failing to properly register custom directives

Looking to enhance the SEO caching capabilities of my AngularJS website, I've embarked on implementing a couple of directives for custom page titles and descriptions. Incorporated within my app config (angular.module('website', [...'we ...

Building a straightforward expandable/collapsible tree view with AngularJS by utilizing a particular data format

Seeking a tree view control that displays as follows: http://plnkr.co/edit/JAIyolmqPqO9KsynSiZp?p=preview +Parent child +Parent child child child child +Parent child child child child child chil ...

Proper utilization of ngIf in conjunction with mat-cell

I am attempting to show a specific value only if the item possesses a certain property, but I keep seeing [object Object] instead. Here is my current method: <ng-container matColumnDef="name"> <th mat-header-cell *matHeaderCellDe ...

Issue with AngularJS: 'FileConstructor is not a valid constructor'

Error Alert: The FileConstructor is not functioning as expected, displaying the error message 'FileConstructor is not a constructor (evaluating 'new File([blob], "filename.png")') Upon researching, I came across a related query Alternative ...