Tips for controlling the last size in a CSS grid

<div class="grid-layout">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/9.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/2.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/3.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/1.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/4.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/5.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/7.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/8.png">
    <img class="grid-item unview" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/6.png">
    
    ...
</div>

This HTML code snippet displays an image gallery with multiple images. The images are structured in a grid layout using CSS.

body {
  font-family: sans-serif;
  background-color: #1b1b1b;
}

.grid-layout {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-gap: 10px;
  grid-auto-rows: minmax(180px, auto);
  grid-auto-flow: dense;
  padding: 10px;
}

.grid-item {
  border-radius: 5px;
}

...

The CSS code provided styles the grid layout, defines image properties, and creates a grayscale effect on hover for the images.

$(document).ready(function () {
    $(".grid-item").mouseover(function () {
        $(this).addClass("span-2", 1000);
        $(this).removeClass("unview", 1000);
    });

    $(".grid-item").mouseout(function () {
        $(this).removeClass("span-2", 1000);
        $(this).addClass("unview", 1000);
    });
});

This Javascript code adds functionality to the image gallery. It enlarges images on hover and reverts them to the original size on mouseout.

The developer is seeking assistance to resolve an issue with mouse hover effects on the grid gallery. Any help or suggestions are appreciated!

Check out the code on CodePen

Answer №1

To implement mouse event functionality in your JS file, you can try the following solution:

    $(document).ready(function () {
    $(".grid-item").mousedown(function () {
        $(this).addClass("span-2", 1000);
        $(this).removeClass("unview", 1000);
        $(this).focus();
    });

    $(".grid-item").mouseup(function () {
        $(this).removeClass("span-2", 1000);
        $(this).addClass("unview", 1000);
    });
});

Feel free to experiment with different mouse events to find the best solution for your needs.

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

Struggling to insert a span element into an anchor tag within a dynamic WordPress navigation menu

I am currently attempting to insert a span tag within a tags in the secondary navigation located on the second level of the following page URL. Thus far, I have only discovered methods for adding span tags to the main navigation as well as child and grand ...

Executing a TypeORM query with a distinct clause that ignores case sensitivity

I am attempting to construct a TypeORM query builder that pulls data from a postgresql database to retrieve all unique names. Here is how my query currently looks: names = await this._context.manager .getRepository(Names) .createQueryBuilde ...

Utilizing Cordova and AngularJS to efficiently retrieve JSON data through XMLHttpRequest in a factory

I've encountered an issue while attempting to retrieve a JSON from an API using XMLHttpRequest within a factory. Despite the debug logs suggesting that everything is functioning correctly, I keep getting an "undefined" response. Below is the code for ...

SystemJS is loading classes that are extending others

In my Angular2 application, I have two classes where one extends the other. The first class is defined in the file course.ts (loaded as js) export class Course { id:string; } The second class is in schoolCourse.ts (also loaded as js) import {Cours ...

Issue with updating dropdown values in real-time in React

I am a beginner with React and I have a question regarding fetching dropdown values from the backend. Despite using async-await functions, the list is not getting populated with items. Any assistance in this matter would be greatly appreciated. Here is th ...

Retrieve solely the text content from a JavaScript object

Is there a way to extract only the values associated with each key in the following object? const params = [{"title":"How to code","author":"samuel","category":"categoery","body":"this is the body"}] I'm struggling to figure out how to achieve this. ...

Increase or decrease the quantity of items by cloning with Jquery and dynamically changing the ID

Currently, I am working on a jQuery clone project where I need to dynamically add and delete rows. Despite searching extensively on Stack Overflow and Google, I only have a basic understanding of how jQuery clone works. Any suggestions would be greatly ap ...

Navigating advanced search through nuanced filters dynamically with AngularJS

Here you will find the advanced search form: https://i.stack.imgur.com/g7Hiz.png I have successfully created a URL and parameters for document sections, but I am struggling to come up with a solution for managing the "Add Property Restrictions" section w ...

Displaying a div after a successful form submission using Jquery

I created two popup windows. One is used to ask the user whether they want to submit the form, and if they click 'yes', the form is submitted. The issue I encountered is that the other popup window should be shown after the form is successfully s ...

The successful JSON response in an Ajax request is not functioning as expected

I've set up a data table that allows users to add rows by clicking the "plus" button. This triggers an ajax request to a URL with the rowId as a parameter (which corresponds to the specific row where the button was clicked). I expect to receive a JSON ...

Issue with CSS files in Jest"errors"

I'm currently facing an issue while trying to pass my initial Jest Test in React with Typescript. The error message I am encountering is as follows: ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.App ...

Can we incorporate various CSS libraries for individual components on our React site?

Let's say, I want to use different CSS libraries for each of my components - Home, About, Contact. Would it be feasible to utilize material ui for Home, semantic ui for About, and bootstrap for Contact? If so, what is the process for incorporating t ...

Difficulties encountered when initiating CRA using npm start

Hi everyone! I'm dealing with a frustrating issue; every time I try to run npm start I keep encountering the error message below: events.js:288 throw er; // Unhandled 'error' event ^ Error: spawn cmd ENOENT To resolve this probl ...

Modify the border color of a div contained within another div

I recently incorporated a Vue component (available at ): <vue-editor id="description" name="description" :class="{'uk-form-danger': errors.has('description') }" v-model="description" :editorToolbar="customToolbar" v-validate="' ...

What is preventing me from being able to effectively transmit the array using the POST method in Express?

As a newcomer trying to learn Express, I believe I am on the right path, but I am currently facing some challenges with the POST method. The issue I'm encountering is as follows: Whenever I send a POST request to an HTTP file, I receive an empty ob ...

AngularJS Error: $interpolate:interr - Encounter with Interpolation Error

Having some trouble embedding a YouTube video into my website using AngularJS. Keep receiving this pesky error: Error: $interpolate:interr Interpolation Error Any idea why this error is popping up and how I can resolve it? Just trying to add the video... ...

Preventing PHP Form Resubmission and Addressing Unusual Problems

Let's keep this brief. This is the code I've been working on: <?php if ($_POST['title'] != 'Title' && $_POST['date'] != 'Date') { $fileName = 'blog.txt'; $fp = fopen('blog.txt', &ap ...

Issue with Firefox position: absolute not producing the desired outcome

I am working on a webpage where I want to put a label over an image. I was able to achieve this using position: absolute for the label and float: left for the img tag. This method worked perfectly in most browsers, except for Firefox (both version 3 and 4) ...

"The function within the Sails.js model is not properly returning a value when rendered

Within my Sails.js application, I am currently attempting to retrieve the total number of users that have been approved in my database and utilize this count variable within my view by employing the count() query. Below is the snippet of code present in my ...

Is there a way to modify the CSS display property upon clicking a link or button?

I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked. I am trying to use the click event on the link to change the display prop ...