Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting an element on mouse click overlapped by another transparent div


I am working on a dashboard where user can drag and drop elements to create html pages.Now,he can have multiple images using an image component.We have managed to calculate the z-index of the images and they can be adjusted using up-down keys.

Issue:
The issue we are facing is when we select a image component we attach a dotted layer above it for helping the user to easily drag and resize it.If the user places the images as shown in the image belowoverlapping elements

we are not able to select the inner image again because the z-index of the selection div(the one with the blue dots) is(has to be) the highest(highest bcoz we have to use it for all components).So if I try to select the inner image now it cannot be selected.How can I handle the situation? For reference it works on this site as expected.
I believe we have get the element under the parent when it is clicked.But not sure how!We are using javascript,jquery to handle the events.

enter image description here

like image 801
coderunner Avatar asked Nov 13 '22 12:11

coderunner


1 Answers

You can use JavaScript or jQuery to get the position of the inner image, and when the user clicks on the outer image, check to see whether the mouse position lies within the range of the smaller image. The range can be calculated with the position, width, and height of the inner element.


To get the element's position: use jQuery .offset() or .position() (The former is relative to the document, the latter to the parent).

To get the mouse position: http://docs.jquery.com/Tutorials:Mouse_Position

like image 78
Alfred Xing Avatar answered Nov 15 '22 05:11

Alfred Xing