The initial responsive card doesn't show up on mobile devices until the screen is tapped

Check out this page: and view the source code. The first card doesn't appear until I scroll or tap on the screen, unlike the original codepen (https://codepen.io/Katiae/pen/zwjmbW) which works flawlessly. Any ideas for a solution? The only modification I made to the page is adding a navbar. Thank you in advance.

    @import url('https://fonts.googleapis.com/css?family=Raleway');

// Colors
@dark-blue: #32325d;
@gray: #f8f8f8;

// Mobile first
*,
*::before,
*::after { 
  box-sizing: border-box;
}

html {
  background-color: @gray;
}

body {
  padding: 2rem 0.5rem;
  font-family: 'Raleway',Sans-serif;
  color: @dark-blue;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  margin: 0;
  @media(min-width: 40rem) {
    padding: 2rem;
  }
}

//Flex container
.container {
  display: flex;
  -webkit-display: box;
  -moz-display: box;
  -ms-display: flexbox;
  -webkit-display: flex;
  flex-wrap: wrap;
  padding: 0;
  margin: 0;
}

// Cards
.cards {
  display: flex;
  padding: 1rem;
  margin-bottom: 2rem;
  width: 100%;
  @media(min-width: 40rem) {
    width: 50%;
  }
  @media(min-width: 56rem) {
    width: 33.3%;
  }

  .card-item {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    width: 100%;
    border-radius: 6px;
    box-shadow: 0 20px 40px -14px rgba(0,0,0,0.25);
    overflow: hidden;
    transition: transform 0.5s;
    -webkit-transition: transform 0.5s;

    &:hover {
      cursor: pointer;
      transform: scale(1.1);
      -webkit-transform: scale(1.1);
      .card-image {
        opacity: 1;
      }
    }
  }

  // Content
  .card-info {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    padding: 1rem;
    line-height: 1.5em;
  }

  .card-title {
    font-size: 25px;
    line-height: 1.1em;
    color: #32325d;
    margin-bottom: 0.2em;
  }

  // Images
  .card-image{
    height: 200px;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 6px 6px 0px 0px;
    opacity: 0.91;
  }
}

Answer №1

Before the script starts running, make sure your page is fully loaded with the following steps:

$(document).ready(function () { 
  var images;

  images = ["https://fiftyallstars.com/Images/fitness/s1.jpg", 
  "https://fiftyallstars.com/Images/fitness/s2.jpg", 
  "https://fiftyallstars.com/Images/fitness/s3.jpg", 
  "https://fiftyallstars.com/Images/fitness/s4.jpg", 
  "https://fiftyallstars.com/Images/fitness/s5.jpg", 
  "https://fiftyallstars.com/Images/fitness/s6.jpg",
  "https://fiftyallstars.com/Images/fitness/p1.jpg", 
  "https://fiftyallstars.com/Images/fitness/p2.jpg", 
  "https://fiftyallstars.com/Images/fitness/p3.jpg", 
  "https://fiftyallstars.com/Images/fitness/p4.jpg", 
  "https://fiftyallstars.com/Images/fitness/p5.jpg", 
  "https://fiftyallstars.com/Images/fitness/p6.jpg",
  "https://fiftyallstars.com/Images/fitness/f1.jpg", 
  "https://fiftyallstars.com/Images/fitness/f2.jpg", 
  "https://fiftyallstars.com/Images/fitness/f4.jpg", 
  "https://fiftyallstars.com/Images/fitness/f5.jpg", 
  "https://fiftyallstars.com/Images/fitness/f6.jpg",
  "https://fiftyallstars.com/Images/fitness/d1.jpg", 
  "https://fiftyallstars.com/Images/fitness/d2.jpg", 
  "https://fiftyallstars.com/Images/fitness/d3.jpg", 
  "https://fiftyallstars.com/Images/fitness/d4.jpg", 
  "https://fiftyallstars.com/Images/fitness/d5.jpg", 
  "https://fiftyallstars.com/Images/fitness/d6.jpg"];

  $('div.card-image').each(function() {
    var random_image_index;
    random_image_index = Math.floor(images.length * Math.random());
    return $(this).css('background-image', 'url(' + 
     images[random_image_index] + ')');
  });

})

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

Issue with Shaking UI Elements in JQuery

When utilizing jQuery UI's shake effect, the element moves to a new line, shakes, and then moves back. I've experimented with changing the position CSS properties, but haven't been able to find an elegant solution without resorting to hacks. ...

Issue with Bootstrap container's max-width not functioning

After implementing the code in the following manner: <link href="css/bootstrap.css" rel="stylesheet" type="text/css"> <link href="css/bootstrap-responsive.css" rel="stylesheet" type="text/css"> <style type="text/css"> .con ...

Tips for refreshing only a portion of a webpage using JavaScript/jQuery

I have two distinct navigational sections on my website. The left column has its own navigation menu, while the right column (main content area) contains a separate set of links: My goal is to click on a link in the left-hand sidebar (such as "Resume", "E ...

Troubles with CSS grid design

Could someone assist me with my grid layout for a project on free code camp? I am trying to display 3 of my portfolio pages in a row using a grid layout, but I'm having trouble getting the middle page to align properly with the others. Since I am new ...

- Challenges with internal systems

I have a dialog window where I want to display a confirm dialog when clicking Cancel. To achieve this, I am creating a div element with some text that should be shown in the confirm dialog. However, the issue I'm facing is that the text intended for t ...

Activate an iframe upon changing the media query

I am currently working on a webpage where I have included an image within an iframe. I am looking to change the content displayed inside the iframe based on different media query breakpoints. For instance, if the viewport has a minimum width of 900px, I ...

Challenges with Hangman in JavaScript

As a beginner in JavaScript, I recently developed a simple hangman-like game. However, I encountered some challenges that I need help with. One issue is related to my lettersGuessed array. Currently, the array displays every time a key is pressed and repea ...

CSS - fixed table headers

Check out my CodePen example here - Code In this demo, I have a table inside a container where the table is larger than the container. As you scroll horizontally, both the table and headers move accordingly. However, when scrolling vertically, I want th ...

problem with the video pathway in the javascript document

I'm currently in the process of putting together a Video gallery playlist using HTML, CSS, and JavaScript. So far, I've set up the html and css files along with two js files. The first js file contains all the video information as shown here: ...

What could be causing the issue of $.ajax being undefined while utilizing jQuery in Node.js?

I'm currently testing a module on Node.js that is meant for client-side use. In order to make $.ajax work, I need some guidance. To begin with, I have installed jQuery on the project using: $ npm install jQuery Despite this, when I try to access $. ...

Issues with populating Asp.net Grid using JSON /AJAX

I'm looking for a way to populate a grid using JSON/Ajax without using templates. The rest of the code is functioning properly. Edit: Do I need to bind the grid with DataSource/DataBind? Can it be achieved without doing so? Below is the success func ...

The logo on my header is being covered by the menu due to the CSS code

Check out my website at bee-barcelona.herokuapp.com I'm facing an issue where the menu overlaps with the logo when I resize the browser or view the webpage on a tablet. I want to fix this using CSS. What changes do I need to make to ensure that the e ...

Verify the presence of the element on the webpage before proceeding, utilizing Python to handle the scenario if

Having trouble resolving an issue that involves checking if a specific element is present on a page before executing a piece of code. Currently, when the element doesn't appear, the script fails with a 'Failed to find element' error. This i ...

Is it possible for the jQuery validation plugin to execute a custom method that returns the result of a $.ajax call without relying on the async:false property?

I've recently started using the amazing jQuery validation plugin and it has been quite effective. However, I encountered a challenge with a few fields on my form that require the use of APIs from external websites. Due to the same origin policy, I cou ...

Utilizing JavaScript for manipulating arrays and displaying images

After asking this question previously without a satisfactory solution, I am hoping to provide better clarification. Imagine having an array with 3 items and it lands on 0 - a code is set up to display this in a div. Now, I want the image to be shown righ ...

Issues with html2canvas crashing have been reported specifically on iOS devices

I recently developed a system for a client that enables users to select or upload an image of a car, input a number plate, adjust the positioning of the plate by moving, resizing, rotating, and skewing it as needed, and then download the modified image: E ...

Changing the Speed of CSS3 Transitions Dynamically

As I am working with CSS3 Transitions, my current query pertains to initiating the animation with: -webkit-transform: translate3d(-100%, 0, 0); Is there a method to augment the predetermined speed set using: -webkit-transition: all 10s linear; This tim ...

What is the best way to create a header that displays without the vertical scroll bar?

Is it foolish or out of the ordinary to ask a question without making an effort? I'm looking for a solution to have a header without a vertical scroll bar like in image 2 on the home page design. I want the top yellow header strip to be visible witho ...

After a refresh of the single-page site, the header is not the first thing displayed

Upon refreshing the site, I encounter an issue where the header does not display first. Instead, it directly leads me to the contact section located further down the page. Has anyone else experienced this problem and found a solution? It's worth menti ...

Deactivating any activities performed by elements within a designated container

As I work on implementing an interactive tutorial for a JavaScript-heavy web application, my goal is to highlight a specific container and prompt the user to click on an element within it. Simultaneously, I aim to restrict the user from engaging with any o ...