Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click through div [duplicate]

When on notification hover, i want it to make opacity to semi transparent and being able to click through it like in this notification plugin Pines Notify

I tried using pointer-events:none, but then it disables DOM element, so jQuery isn't working on this element. I need jQuery to execute code when on hover and on hover out. How can it be done ?

like image 241
Dove Avatar asked Sep 05 '13 17:09

Dove


People also ask

How can I duplicate a div onclick event?

To duplicate a div onclick event with JavaScript, we can call cloneNode` to clone an element. Then we can set the onclick property of the cloned element to the same event handler function as the original element. to add a div. Then we deep clone the element by calling cloneNode with true .

How do you replicate a div in HTML?

Copying an element # Now, we can use the Element. cloneNode() method to create a copy. You call the cloneNode() method on the element you want to copy. If you want to also copy elements nested inside it, pass in true as an argument.

Why is Z Index not working?

You set z-index on a static element By default, every element has a position of static. z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.


2 Answers

To be able to click through a div use the following

  1. Hide the overlay div
  2. trigger a click on the covered element
  3. show the div again

http://jsfiddle.net/H6UEU/1/

$('#front-div').click(function (e) {
    $(this).hide();
    $(document.elementFromPoint(e.clientX, e.clientY)).trigger("click");
    $(this).show();
});
$(".tobeclicked").click(function(){
    $("#result").append("clicked<br />");
});
like image 135
Sam Battat Avatar answered Sep 18 '22 23:09

Sam Battat


Using a combination of applying the :hover selector to the parent div and the pointer-events: none directive on the child div.

https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

JSFiddle

HTML

<div class="container">
    <div class="clickthrough">Mouseover</div>
    <button onClick="alert('click!');">Click me</button>
</div>

CSS

.container {
    position: relative;
}

.clickthrough {
    position: absolute;
}

.container:hover .clickthrough {
    opacity: 0.25;
    pointer-events: none;
}
like image 22
thgaskell Avatar answered Sep 22 '22 23:09

thgaskell