Problem with backstretch script (using DIV element as background)

For my website, I am utilizing a fullscreen background with the help of backstretch. The code below works perfectly on one of my websites:

<script>
$.backstretch([
      "images/1.jpg"
    , "images/2.jpg"
    , "images/3.jpg"
  ], {duration: 6000, fade: 750});
</script>

However, on my new website which has a one page layout with multiple divs, the above code does not work. I have tried a different approach where I want separate full screen backgrounds for each DIV:

<script>
 $("#presentation").backstretch("../images/bg-24.jpg");
 $("#presentation2").backstretch("../images/bg-25.jpg");
 $("#presentation3").backstretch("../images/bg-26.jpg");
</script>

Then, I include the following code for each DIV:

<div id="presentation">
blablabla
</div>
blablabla blablabla

Corresponding CSS Code:

#presentation {
    height: 1300px;

}

#presentation2 {
    height: 1300px;

}

#presentation3 {
    height: 1300px;

}

Answer №1

To implement this feature, locate the following code snippet within jquery.backstretch.min.js

return a("body").backstretch(c,b).data("backstretch")

Next, modify the code by replacing "body" with ".backstretch"

Afterwards, assign the .backstretch class to your div element

That's it, you're all set.

Answer №2

There are a couple of options to achieve this.

  1. First, you can relocate the script below the div tag.

  2. Secondly, you can modify it as shown below:

    <script>
     jQuery(document).ready(function($){
       $.backstretch([
          "images/1.jpg"
        , "images/2.jpg"
         , "images/3.jpg"
       ], {duration: 6000, fade: 750});
    });
    </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

Generate a text input field within a dropdown menu

Below is an example of my basic HTML code for a drop-down list: <span id="Div_List"> <label for="Gender">For:</label> <select name="Gender" id="Sex"> <option value="1">1000mtr</option> <option val ...

What is the best method for effectively organizing and storing DOM elements alongside their related objects?

In order to efficiently handle key input events for multiple textareas on the page, I have decided to create a TextareaState object to cache information related to each textarea. This includes data such as whether changes have been made and the previous co ...

Creating interactive dropboxes in PHP and JavaScript to dynamically change options and display the selected value

Currently, I am in the process of working on a dynamic dropdown menu that involves select boxes. These values are being pulled directly from a MySQL database (if you're interested, here is how I set up the database). I have successfully retrieved and ...

Footer alignment issue when using react-full-page is causing it to not lineup at the bottom of the page

Currently, I have integrated the react-full-page package into my project. However, after adding the Footer to the routes, I noticed that the footer is only visible in the second section of the page and does not appear at the bottom as expected. If you wan ...

JavaScript and jQuery are lightning fast, especially when the page is reloaded

I am currently working on a responsive website that uses liquid layouts. I have encountered challenges when incorporating images in the design, especially when dealing with different browsers like IE, Firefox, and Chrome. Recently, I faced another issue w ...

Is there a way I can detect a browser timeout and display a custom error message?

My webpage in classic asp contains a link to a local IP address, shown below: <a href="http://192.168.1.89">Link</a> When the local IP address is not available, the web browser eventually times out and shows its own error message. I ...

Using an if else statement in JQuery may not produce the desired results

Hello, I'm currently working on creating a login screen using php & mysql with Jquery(ajax). However, I seem to be encountering an issue with the if else statement in my code. Below is the snippet of my code: $("#btnLogin").click(function(){ ...

The code encountered an error because it was unable to access the property 'style' of an undefined element on line 13 of the script

Why is it not recognizing styles and showing an error? All paths seem correct, styles and scripts are connected, but it's either not reading them at all (styles) or displaying an error. Here is the html, javascript, css code. How can this error be fix ...

Overlapping divs are observed when utilizing absolute positioning in CSS

I am facing a challenge with placing the div identified by our_team below the div with the ID of services. When I use absolute positioning, the former ends up overlapping the latter. The services div transitions to display information when hovered over du ...

Is the Button Class failing to retrieve the entire length of the div element?

I'm having an issue with the full length of the div not applying to the button inside. Can someone help me troubleshoot this problem? <div class="col-md-3 col-sm-6 text-center card"> <button type="button" class="btn btn-primary" data-toggl ...

Issues with Codeigniter's ajax pagination search functionality failing to display search results as

For my Ajax pagination, I referred to this site and made some modifications: Everything was working well until I encountered an issue with the pagination after performing a search. For example, when I conduct a search, the pagination links appear correct ...

Troubleshooting dropzone configuration issues and encountering the error message "Dropzone already attached"

I've been utilizing dropzone to manage image uploads on the front-end of my website. Initially, everything was running smoothly while using it as a CDN in the head section. However, I recently attempted to download and integrate it into assetic like t ...

How can I modify the navbar-collapse in Bootstrap to alter the background color of the entire navbar when it is shown or open on a mobile screen?

Can anyone tell me how to change the background color of the navbar when the navbar-collapse is displayed? I want one background color when the navbar-collapse is shown and a different color when it's collapsed. Is there a way to achieve this using C ...

Utilize jQuery to conceal the submit button of a form while maintaining its functionality

Is there a way to conceal the form submit button while still maintaining its ability to function when pressing Return/Enter? The use of .hide() (or display:none with CSS) eliminates the submit on return functionality. ...

Identify when 2 sets of radio buttons are chosen using jQuery

I need assistance with a webpage that presents the user with two simple yes-no inquiries. Below each question, there are two radio buttons for selecting either yes or no. <p>Question 1: Yes or No?</p> <input type="radio" name="q ...

Is there a way to customize the look of the time selected in the <input matInput type="time" step="1" /> time picker?

Currently, I am utilizing the following code as a time picker in my Angular 9 application. My goal is to modify the selected time's color to a bright blue shade. How can I accomplish this task? <input matInput type="time" step="1&quo ...

The alignment of text in the flex column is incorrect on the right side

The flex column I created is having an issue with the arrow on the right side. It's not displaying properly and is hidden. The arrow should be similar to the one on the left and point to the left direction. I have used left: 0; for the left side and ...

Display a pop-up alert message when the session expires without the need to manually refresh the page

I have a query regarding the automatic display of an alert message. Even though I have set the time limit to 10 seconds, I still need to manually refresh the page for the alert message to appear. The alert message should notify the user that the session ...

Changing jQuery to plain JavaScript in order to show a div element more effectively

I am attempting to toggle a checkbox to display a header or div that is currently hidden. @media screen and (max-width: 639.98px){ #menuPanel{ display: none !important; } } I am encountering an unresolved method error on ready in JQuery, ...

Ways to prevent a centered list from shifting to the right

Although this question has appeared before, I am facing an issue with a list displayed as an inline block for use as a navigation bar. My goal is to center the nav bar on the webpage and ensure it scales down appropriately. <ul class="nav_bar"> ...