Struggling to make the background image appear full screen on the webpage despite implementing a script

Currently, I am in the process of developing a responsive landing page using Bootstrap 4 and I would like to implement a background that changes every few seconds. Although I have managed to make the images change dynamically, I am facing difficulties incorporating the img-responsive class into the design.

<section id="fh5co-home" data-section="home" style="background-image: url(images/pretty-bastard-client-lounge.jpg);" data-stellar-background-ratio="0.5">
    <script>
  var images = [
        "images/pretty-bastard-dallas-print-studio.jpg",
        "images/pretty-bastard-lobby.jpg",
        "images/pretty-bastard-sound-stage.jpg",
        "images/pretty-bastard-studio-walls.jpg",
  ]
  var imageHead = document.getElementById("fh5co-home");
  var i = 0;
  setInterval(function() {
      imageHead.style.backgroundImage = "url(" + images[i] + ")";
      i = i + 1;
      if (i == images.length) {
        i =  0;
      }
  }, 7000);
  </script>

The CSS code for achieving this effect is as follows:

#fh5co-home {
  background-color: transparent;
  background-size: cover;
  position: relative;
  width: 100%;
  color: #fff;
}
@media screen and (max-width: 480px) {
  #fh5co-home {
    background-position: center center;
    background-attachment: initial;
  }
}

Answer №1

There seems to be an issue with the height and timing in this code block. Additionally, there is a missing closing section tag.

<section id="fh5co-home" data-section="home" style="background-image: url(images/pretty-bastard-client-lounge.jpg);"
    data-stellar-background-ratio="0.5"> </section>
<script>
    var images = [
        "images/pretty-bastard-dallas-print-studio.jpg",
        "images/pretty-bastard-lobby.jpg",
        "images/pretty-bastard-sound-stage.jpg",
        "images/pretty-bastard-studio-walls.jpg",
    ]
    var imageHead = document.getElementById("fh5co-home");
    imageHead.style.backgroundImage = "url(images/pretty-bastard-dallas-print-studio.jpg";
    var i = 1;
    setInterval(function () {
        imageHead.style.backgroundImage = "url(" + images[i] + ")";
        i = i + 1;
        if (i == images.length) {
            i = 0;
        }
    }, 7000);


</script>

CSS:

#fh5co-home {
  /* background-color: transparent; */
  background-size: contain;
  background-repeat: no-repeat;
  position: relative;
  width: 100%;
  color: #fff;
  height:1000px;
  background-image: url("images/pretty-bastard-dallas-print-studio.jpg");
}
@media screen and (max-width: 480px) {
  #fh5co-home {
    background-position: center center;
    background-attachment: initial;
  }
}

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 CSS menus with Jquery or JavaScript to include a delay

As someone who is just starting to learn about jquery and JavaScript, I am seeking help in adding some code to a css menu. My goal is to create a delay between options so that users have enough time to select an option without it closing prematurely. After ...

Google information window: clicking a link will trigger a page refresh

I am currently running some tests for a web page that I need to design. As part of this process, I have written some code to add markers on a map and include an Info Window for each marker with specific information: function placeLocationMarker(latitude, ...

What is the best way to verify a v-if condition with an array in Vue.js HTML?

I am looking to dynamically add rows based on multiple options selected from a dropdown menu. When I select one option at a time, I am able to get the desired result. However, when I select multiple options, no rows are added. For example, if I select opt ...

Ways to display object data in a snackbar within an Angular application

I am currently working on a snackbar feature that receives notifications from a Web Service and displays whether the Job Execution was successful or failed. To parse the JSON data, I have implemented the following code: this.messageService.messageRec ...

JQUERY is unable to recognize the property or method 'menu' for this object

How can I create a menu using an existing UL from a large HTML file called index.html? Here is the code snippet: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Menu - Default functionality< ...

Develop an Angular JS directive to create a date input with three separate fields, all

Looking for assistance in creating an Angular-js Directive to manage a three-field date input, I am in need of a directive that addresses the issue described in the following link, http://plnkr.co/edit/lHffXV7xEda0xYorucMe?p=preview I have attempted a f ...

Comparing CSS properties: display:block; and display:table;

Are there distinctions between using display:block; versus display:table;? It seems that the display type of the DOM node containing table-row and table-cell nodes is inconsequential. According to MDN, applying display:table; makes it behave like a table, ...

CSS 4.0 Validation Error: The property name "-webkit-text-decoration" is unrecognized in this context

After completing the Udemy course The Complete ASP.NET MVC 5 Course, I encountered an issue with Bootstrap. Despite having the latest versions of Bootstrap, jQuery, and popper.js installed, the functionality simply did not work as expected on my project. I ...

Steps to retrieve an image from the Vue src directory using JavaScript

I am working on a Vue app and I need to access some image files from an included JS file for different purposes, such as adding images to a canvas element. Usually, this task is simple with code like the following: function getImage() { let img = new Im ...

Showcasing JSON information utilizing an Angular DataTable

My Angular DataTable is not displaying data from a JSON array. The issue may lie in my HTML page. Can you help me identify the problem? Here is the snippet of the HTML file: <tbody> <tr ng-repeat="user in userList"> <td><a c ...

Issue with accessing account using ajax

Attempting to set up a login page using Ajax for the first time, but encountering some issues. The login HTML allows users to input their username and password, with a submit button that triggers a JavaScript script when clicked. However, upon entering t ...

Leveraging shadow components with the Next.js pages directory

I am facing an issue with getting a simple shadcn button to work because I am unable to import the button. Although I am using nextjs 13, I am still utilizing the pages directory. Below is the process of how I installed shadcn. Here is the installation co ...

Combining Json, Jquery Autocomplete, and PHP to customize the displayed search options based on multiple items within the Json data

I have a PHP file that returns an array of results, with the 'Name' field being one of them. I want to customize my jQuery autocomplete feature to only search by the 'Name' field and suggest results based on that. However, once a sugges ...

Having difficulty retrieving precise HTML information for data scraping purposes

I'm a beginner in python and exploring web scraping for a project on . Currently, I'm using selenium to automate the search for a CUSIP and then extract specific details about it. Although I've successfully automated navigation from EMMA&a ...

Angular 5 offers the ability to incorporate dynamic checkbox input into your application

Here is my code snippet: <input [type]="'checkbox'" [(ngModel)]="inputValue"> <p>Value: {{ inputValue }}</p> I'm puzzled as to why the value in inputValue remains unchanged. Can anyone shed light on this? I am unable to ...

Reorganize HTML table rows based on the last row within a rowspan

I would like to organize the data in the table below according to the values in the last row of a rowspan. https://i.sstatic.net/R9OBF.png Looking at the image, I am aiming to sort the table based on the "Cumulative hours" value. Here, I have implemented ...

"Encountering a net::ERR_UNKNOWN_URL_SCHEME error message when making an Ajax post request

I'm encountering an issue while attempting to make a post call using Ajax from my frontend to my Express server. The error message I'm getting is net::ERR_UNKNOWN_URL_SCHEME. Here's the code snippet for the Ajax request: function sendStep ...

"Silent Passageway: Connecting Node JS to ASW RDS MySQL Through a Secret

I am currently collaborating on a project with a partner. The backbone of our project is node js, and we are using an AWS RDS MySQL DB for our database. Our main challenge lies in establishing effective communication with the DB through SSH within NodeJS. ...

Guide to incorporating d.ts file for enhancing intellisense in VS Code using a method akin to the NPM approach

In my nodejs project (in JS), I find myself relying heavily on node global variables. Despite receiving warnings against using globals, everything works well except for one thing: The lack of intellisense for globals. Every time I need to use a global fu ...

Is there a way to transfer gulp.watch() to a pipe?

Currently, I have a basic task set up for linting changed JavaScript files: gulp.task('default', function() { // monitor JS file changes gulp.watch(base + 'javascripts/**/*.js', function() { gulp.run(&ap ...