Border Effect Resembling Windows Tiles

When you hover your mouse over a tile in Windows, a cool effect happens:

  1. Hovering outside the tile, but within the container area:

https://i.sstatic.net/yZk9f.png

  1. Hovering inside a tile:

https://i.sstatic.net/LoSmk.png

  1. Hovering outside a tile at its mid point, causing opposite sides to light up:

https://i.sstatic.net/K65cL.png

I'm looking for a way to recreate this effect using CSS and/or JS. Here are some assumptions:

a) Tile positions are fixed
b) Row and column numbers can be accessed with JS
c) All tiles have identical dimensions
d) Container is fully filled with no empty spots

My Approaches:

Initially, I added a mousemove event listener on the container that looped through all tiles to apply the effect based on mouse position. However, this became slow with more tiles.

Next, I attempted calculations with mouse coordinates relative to the container to identify nearby tiles, but ran into issues, possibly due to incorrect math.

Summary:

Seeking a quicker method to replicate the Windows tile hover effect, even if it's a basic version as long as it looks visually appealing. Any help would be appreciated :)

Answer №1

Check out this creative workaround I came up with. While it may be a bit unconventional, it should get the job done:

const container = document.getElementById('container');
const glow = document.getElementById('glow');

container.addEventListener('mousemove', e => {
  glow.style.left = e.pageX + 'px';
  glow.style.top = e.pageY + 'px';
});

container.addEventListener('mouseenter', () => {
  glow.style.display = 'block';
})

container.addEventListener('mouseleave', () => {
  glow.style.display = 'none';
})
body {
  margin: 0;
  background-color: #111111;
}

#container {
  display: grid;
  grid-template-columns: repeat(3, 150px);
  grid-template-rows: repeat(3, 100px);
  gap: 10px;
  position: relative;
  width: fit-content;
  overflow: hidden;
}

#container>* {
  background: rgb(77, 77, 77);
}

#glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
  background: radial-gradient(#fff, transparent 70%);
  transform: translate(-50%, -50%);
  z-index: -1;
}

#container .vertical {
  position: absolute;
  height: 100%;
  width: 8px;
  top: 0;
  background: #111111;
}

.vertical-one {
  left: 151px;
}

.vertical-two {
  left: 311px;
}

#container .horizontal {
  position: absolute;
  width: 100%;
  height: 8px;
  left: 0;
  background: #111111;
}

.horizontal-one {
  top: 101px;
}

.horizontal-two {
  top: 211px;
}
<div id="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div id="glow"></div>
  <div class="vertical vertical-one"></div>
  <div class="vertical vertical-two"></div>
  <div class="horizontal horizontal-one"></div>
  <div class="horizontal horizontal-two"></div>
</div>

This solution involves creating a div with a white radial gradient that follows the cursor movements. The workaround includes using color-matching bars between each item, which isn't ideal for scalability but gets the job done.

Answer №2

The unique border and background styling known as the "reveal" effect is a key component of the innovative Fluent Design System. Fortunately, you're not alone in wanting to incorporate this eye-catching feature. Check out this helpful project: https://github.com/d2phap/fluent-reveal-effect. It offers a fantastic implementation of the reveal effect that functions smoothly.

For those inclined to tackle the challenge on their own, consider leveraging the mousemove event to track the mouse's movements. By calculating the distance between the mouse position and each element with the reveal effect, you can determine if they are within range for the reveal effect. Once an element is deemed close enough, create a circular gradient at the mouse's location and apply it as the background or border for all elements within the "reveal radius". This method should work effectively for managing numerous items simultaneously.

In addition to handling the mousemove event, be sure to address mouseleave and mouseenter events to prevent the reveal effect from getting stuck along the borders. Keeping tabs on scrolling events is also crucial to avoid the reveal effect lagging behind the user's actions.

An even more efficient approach (although the implementation may pose some challenges) involves creating an image where the reveal effect is illustrated as though it were one cohesive button. Subsequently, selectively "cut out" sections of the image to serve as backgrounds for buttons based on their respective positions. While this method offers enhanced performance, navigating the creation and application of such a surface to your controls might prove complex. In scenarios involving limited items, opting for the initial solution would likely yield better results.

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

Adding Bootstrap component via ajax request

I'm facing an issue with injecting a Bootstrap component using ajax. I usually include a select element like this: <select class="selectpicker" data-width="75%"> Most of the HTML code is generated dynamically through javascript, which you can ...

FInding the inner value of a Vuetify chip

I have a Vue application that utilizes Vuetify chips to display information. I'm trying to log the value inside a specific chip when it is clicked, but I keep getting an undefined error when trying to access the array where the information comes from. ...

Is it possible to create a stylish box for an HTML form?

I'm trying to figure out how to put a form inside a box or have a border around it, but I'm stuck. I want the background to be white and was considering using a transparent option. Are there any experts out there with some simple ideas on how to ...

Vue JS encountering Slack API CORS issue while using axios

I am currently developing an application using Capacitor JS & Nuxt JS to interact with the Slack API for setting my Slack status. I have successfully created a Slack App and obtained a xoxp- token, which works perfectly when sending a POST request via Post ...

Rendering DataTable content seamlessly from a different webpage using JavaScript without sacrificing control

Is it possible to dynamically call HTML content from Page2.html into Page1.html by utilizing DataTables (https://datatables.net/)? Page1.html <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" c ...

The page you are trying to access does not support the HTTP request method 'GET'. Please try a different method to access the page

I have been attempting to incorporate AJAX for asynchronous communication with the server. However, I keep encountering the following error message. Any insights on how to resolve this issue? org.springframework.web.servlet.PageNotFound.handleHttpReques ...

Retrieving data from a specific field within a table cell

Why does the value of the select box not get passed in my form scope when it is within its own table cell, but works when the whole form is in a single table cell? Below are examples of working and non-working code: WORKING <tr> <td> ...

What steps can be taken to stop the update function from inserting data into MongoDB from a Meteor application

Within my Meteor method, I have implemented a function to check for existing documents. If the document is not found, it gets inserted into the database. However, if it is found during a second attempt, the document is updated and a new one is also inserte ...

Manipulating attribute values using Jquery

Currently, I am attempting to switch the src value of an iframe when a link is clicked by replacing it with the href from that link. By preventing the default action upon clicking the button, I can successfully update the src value with the url provided. H ...

Need Some Help Reversing the Direction of This CSS Mount Animation?

Exploring this fiddle, I encountered a small div showcasing an opacity animation. The animation smoothly executes when the state transitions to true upon mounting the component, causing the div to fade in beautifully. However, I faced a challenge as the an ...

What is the process for using the scrollIntoView function on an svg element like a rectangle?

I have a graph panel with an SVG. The nodes in the SVG are listed in a separate panel. I would like for when a node is clicked in the node list, the SVG will scroll to that specific node. Each node is represented by a rectangle shape. However, I noticed th ...

Is there a more effective approach to managing an array of objects retrieved from an API call?

I'm attempting to extract an array of names from a JSON response that contains an array of objects, but I'm running into issues. When I try to print the array, it shows up empty. Is this the correct way to go about it? There don't seem to be ...

"Enhance your online shopping experience with a React.js popup modal for

In the midst of developing a shopping cart, I find myself facing a challenge in making the modal pop up when clicking on the shopping cart icon. The semantic-ui documentation for modals has not provided clear instructions on achieving this functionality, s ...

Is it possible to use a += operator with attr() and val() functions in JavaScript?

Ever since I switched to jQuery, my development process has significantly sped up. However, there is one task that has become a bit more time-consuming: appending a string to an attribute or value. For instance, if you wanted to add a letter to the value ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...

JavaScript forEach functionality is not compatible with Dynamics CRM 2016

I'm currently working on writing some JavaScript code for a ribbon button in Dynamics CRM 2016 that will extract phone numbers from a list of Leads displayed in the Active Leads window. However, I've encountered an error message when attempting ...

What is the best method for accessing OpenWeatherMap details via JSON?

I am facing a challenge in JavaScript as I attempt to create a program that fetches weather information from OpenWeatherMap using JSON. My experience with JSON is limited, but I believe I have a grasp of the underlying concepts. Despite this, when I trigge ...

An error is thrown when trying to retrieve Objects: Uncaught TypeError - Object function ParsePromise()

By obtaining a Document object with its id, the following code proceeds to locate corresponding sections based on the object. The document identifies a Parse object and document.toJSON converts this into a Javascript object. Furthermore, sections represent ...

Center align `div 1` with CSS and right align `div 2`

Take a look at this code snippet: http://jsfiddle.net/zygnz/1/ <div class="container"> <div class="left"> LEFT </div> <div class="right"> RIGHT </div> </div> Is i ...

Tips for updating the server without having to reload the page using vuejs

I am currently developing a CRUD application using vue-cli and Node.js on the server side. Here is a snippet of the form I have created: <template> <div id="formRoot"> <div class="form" > <form @submit.prevent="sendToTable ...