Transition smoothly between HTML pages by using a script to fade in and out while changing images from an array

I am facing a small issue. I have successfully implemented a fadeIn and fadeOut effect on an entire page by clicking HTML links. However, I now want to dynamically change the images associated with these links using an array.

Here is the code for transitioning between pages in HTML:

Script

$(window).load(function(){

$("#overlay").fadeOut(1500);
$("a.transition").click(function(event){
    event.preventDefault();

   linkLocation = this.href;
  $("#overlay").fadeIn(1000, function() {
window.location = linkLocation;

  return false;
    });
});
});

Css

#overlay {
  position: fixed;
  top: 0; left: 0;
  background: #fcc916 url(img/logo/blablabla.png) no-repeat center center;
  /*background: #ffffff;*/
  width: 100%;
  height: 100%;
  z-index: 314159;
}

html

<div id="overlay"></div>

I understand that I need to create an array of images and retrieve them using getElementById, but I am unsure of how to proceed...

Thank you for your valuable assistance and apologies for any language barriers!

Answer №1

Experiment with...

$("#overlay")
    .attr("style", "background: #fcc916 url(img/logo/" + fromarray[i] + ".png) no-repeat center center");

You can use this code to dynamically change the background image using jQuery. The '.png' part of the URL can be replaced with values from an array.

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

Dividing a JSON array by a specific key using lodash underscore

I'm on a quest to extract the distinct items in every column of a JSON array. Here is what I aim to convert : var items = [ {"name": "Type 1","id": 13}, {"name": "Type 2","id": 14}, {"name": "Type 3","id": 14}, {"name": "Type 3","id": 13}, {"na ...

Issues with ontimeupdate event not triggering in Chrome for HTML5 audio files

After creating an HTML5 audio element and setting a listener for when its time updates, I have run into an issue where the ontimeupdate function does not fire in Chrome, including Chrome on Android. The audio plays without any issues in other browsers. va ...

Is regex the reason why the website isn't showing up properly on mobile devices?

I encountered an issue on my Vue.js website hosted on Firebase where a blank white page was displayed on mobile devices. After some investigation, I traced the problem back to two objects declared in the data function of one of my components: re: { you ...

What is the best way to align my clip-path's text with the center of the viewport and ensure that all of the clip-path's text is visible?

Check out my React component demo: https://codesandbox.io/s/epic-brown-osiq1. I am currently utilizing the values of viewBox, getBBox, and getBoundingClientRect() to perform calculations for positioning elements. At the moment, I have hardcoded some values ...

Convert time display to a 24-hour format using JavaScript

I managed to convert the time format from GMT to my browser's local time using the following JavaScript code: var newDate = new Date(timeFromat); timeFormat = newDate.toLocaleString(); Now, I want to change the time format to a 24-hour clock format ...

.after() function not behaving as expected

Working on a chrome extension, I encountered a snippet of code: $('a').filter(function() { return $(this).html().match(/myexpressionhere/); }).after().append('<img src="myImage" />'); Upon execution, the code successfully adds m ...

The Hidden Power of jQuery: Unleashing the Full Potential of .text()

I'm trying to make two values equal, but it's not working... var rowID = $("#@idSelectObjectGuid").val(); $($(".ls-grid-body tr").children("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="240a64524770454648410a74564d ...

Filtering JSON data with JavaScript

Looking to group data in AngularJS using UnderscoreJS. Here is the JSON data: data = [ { "Building*": "Building A", "Wing*": "Wing C", "Floor*": "Floor 3", "Room Name*": "Room 3", "Room Type*": ...

A guide to efficiently passing props in a Vue.js application connected to Express with MongoDB

I am in the process of creating a simple chat application using Vue.js, Node, Express, and MongoDB. The app starts with a welcome page where users can input their names (refer to: Welcome.vue). After entering their name, users are directed to Posts.vue, pa ...

How can I capture the ng-click event in AngularJS when using bootstrap-select for styled select inputs?

After selecting an option, I am facing an issue where I cannot capture the ng-click event when a user chooses a value from the drop-down menu. This is because the select option has been altered by bootstrap-select, as the default select option does not sup ...

the click event fails to trigger when the id or class is modified

Hey there, I'm new to working with jquery and I've encountered a problem. Here's the code snippet: http://jsfiddle.net/8guzD/ $('#test.off').click(function(){ $(this).removeClass('off').addClass('on'); }) ...

Received an undefined response from jQuery Ajax request to a webservice

I'm facing a small issue with my webservice call. I've thoroughly debugged it and confirmed that the webservice is being called with the correct value and returning the expected result. However, when I check the alert message in the completed fun ...

Skipping over jQuery's if-else statement

Why does my if else statement only check the first condition? It seems to skip the rest. I have set up 3 variables to simplify writing the conditions. Below you will find the HTML and JQUERY code: <select id="tToth"> <option value="0">Select ...

Wordpress isn't loading CSS as expected (I believe...)

Recently, a wordpress based website I am working on suddenly stopped pulling the CSS files...or at least that's what it seems like. I can't post a screenshot of the wordpress admin dashboard because I don't own the site and my boss might no ...

Positioning buttons and elements on top of a BootstrapVue Carousel slide: a handy guide

Can different elements be positioned on the BootstrapVue Carousel slide without restrictions, such as in any corner or position? I have attempted to accomplish this by nesting additional elements within <b-carousel-slide></b-carousel-slide> ...

"Troubleshooting: Why isn't the AJAX Live Search displaying any

When I try using the live search page in livesearch.php by typing entries into the input box, I am not seeing any results displayed below it. Below is the HTML code and script in search.php. search.php <!DOCTYPE HTML> <html> <he ...

The method this.$refs.myProperty.refresh cannot be invoked as it is not a valid

I have added a reference value 'callingTable' to a vue-data-table (using vuetify) like so: <v-data-table :headers="callingTableHeaders" :items="getCallingDetails" class="elevation-1" ref="callingTable&quo ...

How does jquery's removeClass function on a button continue to function smoothly even after an ajax call

Code Snippet: <span class="input-group-text"> <button type="button" class="btn btn-outline-danger btn-sm owner_button owner_check" name="owner_check" > <i class="far fa-check-circle"></i> </button> </span> ...

Obtain the dimensions (width and height) of a collection of images using Angular and TypeScript

Currently, I am facing an issue with my image upload functionality. My goal is to retrieve the width and height of each image before uploading them. However, I've encountered a problem where my function only provides the dimensions for the first image ...

Choose an option from the dropdown menu when clicking on the radio button

My issue involves a drop-down menu along with two radio buttons, each with two values: jQuery('input[type=radio][name=radio_type]').change(function(e) { var value = jQuery(e.target.value); jQuery('select[name="optType"] option:selecte ...