最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable all mouse events except click? - Stack Overflow

programmeradmin0浏览0评论

I want to disable all mouse events except click, I have this:

.info {
    -webkit-transform: rotate3d(1, 0, 0, 90deg);
    transform: rotate3d(1, 0, 0, 90deg);
    width: 100%;
    height: 100%;
    padding: 20px;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 4px;
    pointer-events: none;
    background-color: rgba(26, 188, 156, 0.9);
}

but pointer-events: none; disables all events.

I want to disable all mouse events except click, I have this:

.info {
    -webkit-transform: rotate3d(1, 0, 0, 90deg);
    transform: rotate3d(1, 0, 0, 90deg);
    width: 100%;
    height: 100%;
    padding: 20px;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 4px;
    pointer-events: none;
    background-color: rgba(26, 188, 156, 0.9);
}

but pointer-events: none; disables all events.

Share Improve this question asked Jun 24, 2015 at 20:27 ნიკა ბერიძენიკა ბერიძე 1231 gold badge1 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 10

The pointer-events attribute only has three properties:

  • none,
  • auto,
  • inherit

So if you attach

    pointer-events: none;

to an element all events will be disabled.

    pointer-events: auto;

however restores all default functionality and is good for if an element's parent has pointer-events: none.

A workaround that I think you'd find useful (aside from some JavaScript manipulation), is to wrap your objects in a parent container and add

    pointer-events: none;

to that parent container and use:

    pointer-events: auto;

on .info and add .info to the child elements of the container.

It won't accomplish exactly what you're looking for but it will replicate that click only illusion.

One approach is to first make all instances of any one elements as :

 pointer-event:none

For example here I am making all img tags as pointer-event:none in css files:

img{
        pointer-event:none
     }

then you have to enclose your clickable element( for e.g img ) inside another tag(like div, span )

For example:

<div class="enclosing-img-class" click="sampleEvent()">
  <img src="sample.png" alt="No Image available">
</div>
发布评论

评论列表(0)

  1. 暂无评论