Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect wether the mouse is over the :before or over the :after part of an element

I have this CSS to define drop areas, where a user can either drop a section before or after existing sections.

.section:before,
.section:after {
    content: "[insert here]";
    height: 64px;
    line-height: 56px;
    width: 100%;
    display: block;
    border: 3px dashed #aaa;
}

Using JavaScript + JQuery here is the drop listener, that detects the element currently under the mouse:

elem.on('drop', function(e) {
  e.preventDefault();

  var container = $(elem[0].elementFromPoint(e.clientX, e.clientY));
});

However container would be the same element for both the :before and :after case.

How will I be able to know if the user has dropped before or after the section?

like image 985
JochenJung Avatar asked Jan 03 '18 08:01

JochenJung


1 Answers

::before and ::after are css pseudo-elements which javascript do not know about. For javascript, they are both their parent element.

You might want to use real html elements to do that.

like image 165
kLabz Avatar answered Sep 25 '22 02:09

kLabz