Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep Hover attribute with Pointer-event: none

I have a button underneath a background image. To make the button clickable, I added a "pointer-event: none". However, I also want a sprite image, where I change the background image on hover, which the pointer-event also disables. Is there a way to keep the hover attribute of an element, while making clicks go through it?

I searched and tried jquery unbind click and returne false when #cover_button is clicked, but it didn't work.

Here's my code. If I keep the pointer-event: none I can click the button underneath my background image. But that would disable the hover attribute. If I remove it I won't be able to click.

#cover_button {
    pointer-event: none;
    position: absolute;
    width: 46px;
    height: 24px;
    left: 0;
    top: 0;
    background: url(http://s13.postimg.org/bqxlnbfs3/Like.png);
}

#cover_button:hover {
    background: url(http://www.moronacity.com/tech-journal/images/2011/February/small-Facebook-like-button-counter.gif);
}

Edit:
Here's a fiddle: Clickable but not hoverable http://jsfiddle.net/3PXTK/1/

Here's another: Hoverable but not clickable (I just removed the pointer-events: none) http://jsfiddle.net/3PXTK/

like image 975
user2534878 Avatar asked Jul 12 '13 23:07

user2534878


People also ask

How do I set hover none?

One method to do this is to add: pointer-events: none; to the element, you want to disable hover on. (Note: this also disables javascript events on that element too, click events will actually fall through to the element behind ).

What is the default pointer events?

Default Pointer Events on an element corresponds to the CSS pointer events property. It controls whether or not an element will "pass through" clicks to elements that are underneath it (that is, elements that have a smaller z-index). For example, in the following canvas an image sits over a button element.


1 Answers

You cannot not have a cookie and eat a cookie. First you have to understand how pointer events works:

none prevents all click, state and cursor options on the specified HTML element

That means no click, no hover, no active - nothing with cursor. You can not say ok, I just want hover and nothing else.

BTW. FB do it like this because they don't allow any changes in like button. You cannot change a look, cover it etc.

like image 109
Kinga Avatar answered Oct 10 '22 05:10

Kinga