Dynamic Image Grid Created Using JavaScript Glitches

My dilemma involves using JQuery to create an HTML grid of images styled with Flex Boxes. The setup works perfectly on desktop, but when viewing it on mobile devices, the images begin to act strangely - jumping, overlapping, and even repeating themselves in bizarre ways. At times, only a portion of one picture appears on top of another, creating an unintended visual spectacle.

To witness this issue for yourself, feel free to explore the problem on the jsfiddle link provided below and try refreshing the page multiple times quickly.

The images used are pictures of people's faces, which admittedly results in a comical display. However, despite the humor, fixing this bug is essential. My hunch is that the problem lies in my approach to constructing the grid randomly using JQuery:

var a={};
$(document).ready(function(){
    a.team = [
        {'name':'John','title':'Creative Director and Lead Designer','img':'John.jpg'},
        {'name':'Nate','title':'Director of Game Day Operations','img':'Nate.jpg'},
        {'name':'Morgan','title':'Spokesperson','img':'Morgan.jpg'},
        {'name':'Tom','title':'Lead Web Developer','img':'Tom.jpg'}
    ];

    for(member in a.team) a.team[member].ran = Math.random();

    a.team.sort(function(a, b) { return a.ran - b.ran; });

    a.h = '';
    for(member in a.team){
        var h = '';
        h += "<a class='tm-area ongrey' href='/#'>";
        h += "  <div class='tm-pic-area'>";
        h += "      <img src='images/team/"+a.team[member].img+"' class='tm-pic g'>";
        h += "      <img src='images/team/Portrait Frame.svg' class='tm-mask'>";
        h += "  </div>";
        h += "  <div class='tm-info-area'>";
        h += "      <div class='tm-info-name goth'>"+a.team[member].name+"</div>";
        h += "      <div class='tm-info-title euro'>"+a.team[member].title+"</div>";
        h += "  </div>";
        h += "</a>";

        a.h += h;
    }

    $('#icon-grid').html(a.h);
});

The CSS code implemented for styling the grid is as follows:

#icon-grid{
    float: left; display: block; width: 100%;  margin: 10px 0;
    display: -webkit-flex;  display: flex;
    -webkit-justify-content: space-around; justify-content: space-around;
   -webkit-align-content: stretch; align-content: stretch;
    -webkit-flex-wrap: wrap; flex-wrap: wrap;
}
.tm-area{ width: 180px;  margin: 10px; cursor: pointer; display: block; 
    text-decoration: none; color: black;}
.tm-pic-area{ width: 180px; height: 180px; }
img.tm-pic{ width: 178px; height: 178px; margin:1px; 
    position: absolute; z-index: 1; float: left;
    -webkit-transition:-webkit-filter 0.3s ease-in-out;
    -moz-animation: -moz-filter 0.3s; /* Firefox */
    -o-animation: -o-filter 0.3s; /* Opera */
}
.g {
    filter:gray;
    -webkit-filter: grayscale(1);
    -moz-filter: grayscale(1);
}
img.tm-mask{width: 180px; height: 180px; position: absolute; z-index: 2; float: left;}
.tm-info-area{ width: 100%; }
.tm-info-name{ width: 100%; font-size: 20px; font-weight: bold; text-align: center; 
    border-bottom: 2px solid black; margin-bottom: 4px; padding-bottom: 2px; }
.tm-info-title{ width: 100%; font-size: 14px; text-align: center; 
    font-weight: bold; margin-bottom: 4px; }

@media screen and (min-width:0px) and (max-width:400px){
    .tm-area{ width: 140px; margin: 5px; }
    .tm-pic-area{ width: 140px; height: 140px; }
    img.tm-pic{ width: 138px; height: 138px; }
    img.tm-mask{width: 140px; height: 140px; }
    .tm-info-name{ font-size: 16px; }
}

https://i.stack.imgur.com/KFTim.png

This puzzling situation leaves me wondering about the root cause behind these unexpected occurrences.

An updated demonstration can be found on jsfiddle:

https://jsfiddle.net/gux8py6f/7/

https://jsfiddle.net/gux8py6f/7/embedded/result

To experience the issue firsthand, visit the provided jsfiddle link and experiment by rapidly refreshing the page.

Answer №1

The issue that arose was due to the lack of reliability in the gray scale CSS property.

filter          : gray;
-webkit-filter  : grayscale(1);
-moz-filter     : grayscale(1);

To achieve the desired grey-to-color effect on hover, I implemented a workaround by stacking two images on top of each other; one in color and the other in grey. Using JQuery, I created an animation that changes the opacity of the top grey image upon hovering, revealing the colorful version of the image below.

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

What is the best method for seamlessly loading JSON data while transitioning between pages in a jqtouch application?

I've been working with JQTouch for my application. While the demos showed how to retrieve an html file and display it in the user interface, I'm dealing with loading JSON data that I want to incorporate into an existing DIV element. I prefer not ...

Error: karma cannot locate the templateUrl for Angular component

I'm encountering some issues while running tests on angular directives with karma. The problem arises when the directive comes from a templateUrl and is not being translated properly. Here's my karma.conf.js configuration: 'use strict&apos ...

Ensuring the Accuracy of POST Parameters Using Express-Validator

I've been working on adding parameter validation to my Node/Express API by utilizing express-validator. However, I encountered a situation where even though I sent a POST request with a missing "name" field using the curl command curl -X POST -d "foo= ...

Outputting a variable using javascript

My challenge is to efficiently print the contract variable, which contains HTML content fetched from the server. How can I achieve this easily? I want the print window in Chrome to display the document with the contents of my variable when I click a button ...

Troubleshooting Issue with Nested ng-include in AngularJS: Difficulty arises when the parent element with the ng-include attribute is dynamically added using the ng-

Click here to see a demo plunker that will help you understand my issue. On my main page, I have a table. Each table row is followed by a hidden empty row. When the first row is clicked, I use a directive to inject HTML into the empty row below it. Main ...

Exploring AngularJS unit testing: integrating async and await with Jasmine

I'm currently facing a challenge with unit testing my Angular service using the async/await keywords in the respective (Jasmine) unit tests below. The test for the built-in Promise is functioning correctly, however, I am encountering difficulties in g ...

How can I use JavaScript to disable a table row and then save the selected option in a MySQL database?

I have a PHP snippet that dynamically displays table rows. Each row contains a radio button with "Yes" and "No" options. I have implemented a JS function where, upon choosing an option, a pop-up box is displayed. If the user selects the "Yes" option in t ...

Encountering issues with verifying login credentials in Angular 2

Greetings! I have designed a login page where the user will be logged in if the response is successful, otherwise an error message will be displayed. Below is the JSON data with email and password fields: { Email": "<a href="/cdn-cgi/l/email-protect ...

What steps should be taken when encountering the "Cannot Get" error message on a webpage?

Currently, I am in the process of creating an HTML file within xcode with the intention of displaying its contents in the browser. With an empty file as my starting point, the following code was added: <html> <head> <title>HTML is S ...

Utilize Google Tag Manager to search and substitute characters within a variable

Within my GTM setup, I have a CSS selector variable in the DOM. This variable pertains to real estate and specifically represents the price of a listing. My goal is to eliminate the characters ($) and (,) from this variable as part of meeting the requireme ...

Tips for arranging images in a horizontal layout using FlatList in React Native

Is there a way to display feed images horizontally instead of vertically in FlatList? I've tried wrapping the images in a view with flex-direction set to row, as well as adding horizontal={true} to the FlatList, but nothing seems to work. Any suggesti ...

Struggling to animate the selector of a nested div in Jquery?

Despite trying numerous variations, I am struggling to identify the correct selector of a nested div. The goal is to animate this particular div, but since no animations are taking place, I suspect that I have not selected the right element. Here is the a ...

Combining server-side and client-side routing in AngularJS: A comprehensive guide

Currently, I am in the process of transitioning a project to an Angular-based Single Page Application (SPA). The project is originally built using node/locomotivejs and serves templates from the server side. Due to its large size, we are converting it to A ...

Check jQuery radio button selection for each iteration of loop

I am facing an issue with my jQuery code. The code is designed to check radio buttons and show or hide a warning box accordingly when none of the radio buttons are selected in each group. However, I have noticed that when the code runs, it takes the value ...

Using jQuery to obtain the object context while inside a callback function

Suppose I have the following object defined: var myObj = function(){ this.hello = "Hello,"; } myObj.prototype.sayHello = function(){ var persons = {"Jim", "Joe", "Doe","John"}; $.each(persons, function(i, person){ console.log(this.h ...

Error in AngularJS ng-repeat syntax

As a newcomer to AngularJS, I ventured into creating a Bootstrap form with a loop but encountered an error. What could be the mistake I made? <form class="form-horizontal" role="form" name="newForm" novalidate ng-controller="newFormController"> < ...

Are there any known browser compatibility issues with using "./" (dot slash) before HTML files?

Within the realm of shells, using ./ to indicate the current directory is quite common and generally not perceived as risky when specifying a path. On the other hand, in HTML coding, it's typical to omit ./ and instead directly specify the file name. ...

Steps for styling an AngularJS Popup:1. Determine the desired appearance for

I have some code that displays a popup when clicked, along with its automatically generated CSS. I want to be able to make changes to the CSS by adding IDs or classes to it. How can I assign IDs or classes to this element so that I can easily target them f ...

Having trouble clicking or interacting with JavaScript using Selenium and Python

Issue: Unable to interact with elements on a specific webpage after opening a new tab. Using WebDriver Chrome. I can successfully navigate the initial webpage until I click a link that opens a new tab, at which point I am unable to perform any actions. ...

What is the best method for decreasing the space between ordered list elements?

Help with removing unwanted top margin space I have been experiencing an issue where I am getting extra space above the list items when using a ul before an ol. The result is that only the unwanted space appears above the circle and number 1. I attempted ...