A guide to implementing hover and mouse click effects on ImageList using Material UI version 5.11.11

I have successfully created a list of images using MaterialUI, but now I would like to enhance the user experience by adding a mouse hover effect to highlight the image under the cursor. Below is the code snippet for my image list. How can I accomplish this?

<Box
        sx={{
          height: 450,
          marginLeft: "10em",
          backgroundColor: "white",
          display: "grid",
          gridTemplateColumns: {
            mobile: "repeat(1, 1fr)",
            bigMobile: "repeat(2, 1fr)",
            tablet: "repeat(3, 1fr)",
            desktop: "repeat(4, 1fr)",
          },
          [`& .${imageListItemClasses.root}`]: {
            display: "flex",
            flexDirection: "column",
          }
        }}
      >
        <ImageList
          variant="quilted"
          sx={{ width: 2000, height: 1000, margin: "5em" }}
          cols={3}
          rowHeight={500}
          
        >
          {cardsList.map((item, index) => (
            <div>
              <ImageListItem key={index}>
                <img
                  src={"data:image/jpeg;base64," + item.content}
                  alt={item.fileName}
                />
              </ImageListItem>
            </div>
          ))}
        </ImageList>
      </Box>

Answer №1

Altered ImageListItem by implementing a customized version with hover effects as shown below, although I personally do not favor the new approach to styling elements in MUI v5.11

const CustomImageListItem = styled(ImageListItem)(({ theme }) => ({
    "&:hover": {
      cursor: "pointer",
      opacity: 0.8,
      border: `solid 5px red`,
      //boxShadow: `5px 10px ${theme.palette.primary.main}`,
      
    },
  }));

 <CustomImageListItem key={index} >
                <img
                  src={"data:image/jpeg;base64," + item.content}
                  alt={item.fileName} 
                  id={index}
                  onClick={cardSelected}
                />
              </CustomImageListItem>

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

Is there a way to manually change the field color upon approval in AngularJS?

Within my application that utilizes the MEAN stack, I am using AngularJS as the front-end technology. How can I manually change the color representation of a tolerance value to 159.06 in a table? Check out my Plunker for more details. Please refer to m ...

"Is it possible in Typescript to set the parameters of a returning function as required or optional depending on the parameters of the current

I am currently exploring Typescript and attempting to replicate the functionality of styled-components on a smaller scale. Specifically, I want to make children required if the user passes in 'true' for the children parameter in createStyledCompo ...

The draggable function for <text> in SVG is glitchy, causing the cursor to move faster than the text being dragged

Below is a code snippet that showcases an interactive draggable text feature: function DraggableText({ x, y, text }) { const [position, setPosition] = React.useState({ x: x, y: y }); const [isDragging, setIsDragging] = React.useState(false); ...

Personalizing the fileTemplate selection in FineUploader

My English is not the best, so apologies in advance. I'm struggling to customize the FineUploader FileTemplate option. I don't want to use fineUploaderBasic; I want total customization. Initially, I managed to hide the file name and size after a ...

An error is thrown when using less.js

Every time I attempt to add less.js, I encounter an XmlHttpRequest Exception 101. Including the .less file is done using this method: <link rel="stylesheet/less" type="text/css" href="anything.less" /> This issue only arises when I upload the th ...

Using the spread syntax to eliminate a property from an object within a ReactJs element

I'm trying to figure out if it's possible to remove a specific object property using spread syntax when rendering a React component. I want to achieve this without adding too much extra code. Currently, I am utilizing {reset,...inputName} In my ...

Experiencing a problem when attempting to submit a post request on a React application connected to

Could you assist me in resolving the following issue? I am encountering an error when attempting to add a user to the database, showing: "Error:MongoError: E11000 duplicate key error collection: test.users index: username_1 dup key: { : null }" Below is t ...

Align images to the bottom of the gallery only if their heights differ

I'm currently working on an image gallery project and have encountered a problem. When all the image labels are of the same length, they align perfectly. However, if the label is longer than one line, it causes the image to move up instead of creating ...

How can we stop the navigation submenus (ULs) from appearing as if they are floating?

I've created a navigation bar with an unordered list consisting of smaller unordered lists, each with the class "subnav". When the screen is small, the navigation collapses and the menus stack on top of each other. I want the navigation to maintain i ...

methods for transferring javascript variables to modal

<div> <h5> <a href="<?php echo base_url(); ?>/vendor/home/projects" >Return to Projects</a> </h5> <div> <div class="container"> <div class="row"> ...

Adding an event listener to the built-in arrow buttons on the `<input type=number>` element is a simple way to enhance user interaction

<input type="number" id="test"> I'm trying to figure out how to set an event listener for the two arrow buttons on the right of this number input field. Typically, we can use jQuery like: $("#test").on("cl ...

Interactive hover effect in JavaScript displays a larger version of other thumbnails when hovering over a dynamically loaded thumbnail image, instead of its own full-size image

I recently began teaching myself PHP and Dreamweaver with the help of a video tutorial on building data-driven websites using Dreamweaver. My goal is to create a dynamic table with 6 columns and 20 rows. column1 | column2 | column3 | colu ...

How about designing a unique Material-UI button with an SVG?

I am currently working on creating a material-ui button that includes a custom SVG file as the base of the button, shown here: The button will also feature a 'label' like "submit," "OK," or "Cancel." Is there a way to utilize the material-ui but ...

receiving an error message due to attempting to access an

I'm facing an issue with replacing objects in an array using JavaScript. I tried to use indexOf and splice methods, but it's not working as expected. The value returned by indexOf is '-1', indicating that the object is not found in the ...

Encountering difficulties with installing @mui/styles in React deployment

I'm facing issues with installing @material-ui/core or @mui/styles. The versions of React and MUI I am using are as follows: "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1&quo ...

NestJs backend returning empty response to ReactJs frontend communication

My ReactJs frontend (localhost) is calling a NestJs backend: fetch("http://myappherokuapp.com/user/login", { method: "POST", mode: 'no-cors', headers: { 'Content-Type': 'appli ...

The elements from base.html and the extended page are now placed on separate rows rather than on the same row

I'm relatively new to HTML, Jinja, and CSS and have been playing around with creating a webpage that retrieves data from a sqlite3 database. As of now, I am facing some challenges regarding formatting. To assist with table formatting and overall aest ...

Using jQuery, wrap two specific HTML elements together

I am working with a set of elements: <div id="one">ONE</div> <div id="two">TWO</div> <div id="three">THREE</div> <div id="four">FOUR</div> <div id="five">FIVE</div> My goal is to wrap a DIV tag ...

Display a smaller image preview in the product photo gallery

Hey there! I'm currently working on a website and looking to showcase my product in a similar way as shown here: I would like my main image to be displayed with all the other variants of the product image underneath, along with the same visual effect ...

Retrieve the page dimensions from a Material UI component `<DataGrid autoPageSize/>`

When utilizing <DataGrid autoPageSize/>, as outlined in the documentation, you can have a Material UI table that adjusts its page size based on the browser height. However, if you are fetching data from the server progressively, it becomes essential ...