Find the second element beneath the mouse cursor that is not a direct ancestor of the first element

I am currently developing a card drag-and-drop board using HTML5 inspired by Trello.

My focus right now is on connecting the lists to specific list slots/containers.

My challenge lies in determining which list container is positioned beneath the mouse pointer when the list is released (onMouseUp). This information is crucial for attaching the list to the correct container.

At present, I am struggling to identify the container element under the mouse cursor. The issue arises because the list is directly under the mouse when attempting to identify its surroundings.

Obtaining the parent element of the dragged list is problematic since the parent element remains constant while the list is dragged and its top and left attributes are modified.

In essence, I need to identify what lies under the mouse cursor, excluding the list being dragged. When the drag occurs over list slot 1, I need to capture that specific element; likewise, when moving over list slot 2, I need to detect that element.

import React, { useEffect, useState } from "react";

// Rest of the JavaScript code here...

This is where my progress stands at the moment.

Any guidance or assistance would be greatly appreciated.

Answer №1

I managed to resolve the problem by adjusting the pointerevents slots to none while they are being dragged. Then, I set them back to default when not being dragged.

I also made modifications to the onMouseDown and onMouseUp event handler to the body of the page in order to continue detecting the event.

import React, { useEffect, useState } from "react";

export default function Main() {
  // Functionality and state management code goes here

  return (
    <div className={"testing"}>
      <Container >
        <Slot
          slot_id="Slot_1"
        >
          <List></List>
        </Slot>

        <Slot
          slot_id="Slot_2">

        </Slot>
      </Container>
    </div>
  );
}

function List() {
  // Code for List component goes here
}

function Slot(props) {
  // Code for Slot component goes here
}

function Container(props) {
  // Code for Container component goes here
}

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

Fetching the second item within an object using JavaScript

I am trying to retrieve the data from the last month of an API, but I want to avoid hard-coding the date like this: const data = [data.data['Monthly Time Series']['2021-11-30']]. I need a way to dynamically access the 2nd object without ...

How to Fix Owl Carousel Not Displaying in Bootstrap 5

I attempted to use Owl Carousel version 2.3.4 with a CDN, but it doesn't seem to be working. Here is my code, but the carousel is not displaying. Thank you. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3. ...

Updating the CSS link href in ASP.NET using code behind

I'm struggling with changing the CSS href in the code-behind of my .ASPX page. I've tried various methods but haven't found a solution that works as intended. HTML Markup: <link id="linkCSS" runat="server" href='/css/1.css' re ...

Tips for loading a webpage with optimal speed and efficiency

I am inspired by the sleek design of Apple's website and want to replicate some of its features in my project (best viewed on FF, Chrome, Safari): Initially, the page appears empty except for the header - but the final height of the page is already ...

Extracting the call from REST API in JSON format

Working with a third-party database using a REST API, I encountered an error response (as expected). Here is the code snippet: transaction.commit(function(err) { if (err){ var par = JSON.parse(err); \\ leading to error: SyntaxError: Unexpecte ...

Error message: The method app.get() is invalid as it is not a

I'm having trouble using Express in a prototype function ioServer() { } module.exports = ioServer; ioServer.prototype.start = function() { var app = require('express') var http = require('http').Server(app) ...

The process of rendering children elements in React

I have a question about managing children components in React. While there are resources available explaining this concept, I believe a more detailed explanation would be helpful. Let's consider the structure of my React component tree, which looks l ...

Enabling or disabling a button dynamically in Ionic based on a conditional statement

I am looking to dynamically enable or disable buttons based on specific conditions. The data is retrieved from Firebase, and depending on the data, I will either enable or disable the button. For example, if a user passes the First Quiz, I want to enable ...

Creating a customized greeting message using discord.js

I've been working on creating a Discord bot using discord.js, and I'm trying to figure out how to make the bot send a welcome message when a new member joins the server and opens a chat with the bot. The message should be something like "Hi there ...

I am encountering compilation errors while trying to run a basic react-dnd list using typescript

I'm currently working on implementing the beautiful-react-dnd example and encountering some errors: import * as React from 'react'; import { DragDropContext, Draggable, Droppable, DroppableProvided, DraggableLocation, DropResult, ...

What is the best way to show my results in a single line?

$(document).ready(function() { $("#submitForecast").click(function() { return getForecast(); }); }); function getForecast() { var city = $("#city").val(); var days = $("#days").val(); if (city != '' && days != '' ...

What could be the reason for parent props not updating in child components in VueJS?

Hello, I am new to VueJS and encountering an issue. In the main.js file, I am passing the user variable to App.vue using props. Initially, its value is {} The getLoginStatus() method in main.js monitors the firebase authentication status, and when a user ...

"Encountering a hiccup in executing map.reduce

var mapFunction1 = function() { for (var i = 0; i < this.money.length; i++) { emit("balance", this.money[i].amount); } }; var reduceFunction1 = function(keyBalance, valuesBalance) { return Array.sum(valuesBalance); }; db.users.ma ...

Invoke a JavaScript function within a PHP file

My JavaScript file, named "my_js_stuff.js", has the following code: function my_js_function() { jQuery.ajax({ url: my_ajax_script.ajaxurl, data: ({action : 'get_my_comments'}), success: function() { //Do stuff here } }); This file is ...

When utilizing ASP.NET Core Razor pages for file uploads and utilizing AJAX Post to send the file to an IFormFile handler, the request

I have a straightforward task that involves uploading a file and using AJAX to post it to the Index page: <input type="file" id="file-selector" accept=".txt"> Here is the corresponding Javascript: const fileSelector ...

Using a forward slash in the path for the href attribute in a CSS link within an ejs file

Image 1: Configuring express.static for the public folder Image 2: Adding href="/app.css" in post.ejs file Image 3: Final result While experimenting with using /app.css and app.css in the post.ejs file, I noticed that the outcome was consistent with th ...

Web Security Vulnerability: Cross Site Scripting Detected

In our code, we are aiming to prevent XSS (Cross Site Scripting) attacks. However, the solution may involve a combination of JS (JavaScript) and HTML escaping, which could prove to be quite challenging. Below is a snippet that closely resembles our code: ...

The text fields keep duplicating when the checkbox is unchecked

There are check boxes for Firstname, Lastname, and Email. Clicking on a checkbox should display the corresponding input type, and unchecking it should remove the input field. I am also attempting to retrieve the label of the selected checkbox without succ ...

Error: Attempting to access property 'baseHref' of an undefined value is not possible

Creating a webpack configuration for Angular 7 has been my recent project. I found a helpful tutorial on how to customize build configuration at this link. I decided to use the @angular-builders package for this task. Upon checking my index.html file, I m ...

The basic node API request is not showing any information

There is a request in my server.js file var Post = require('./../models/post'); //GET ALL POSTS app.get('/api/posts', function (req, res) { Post.getPosts(function (err, posts) { if(err) { throw err; } ...