How can I pass a click through an element?

后端 未结 4 2200
时光取名叫无心
时光取名叫无心 2020-12-07 00:24

I want to display an image under the mouse (a finger to simulate a touch screen) when a mousedown event occurs and hide it when the mouseup event occurs, but when I do this,

相关标签:
4条回答
  • 2020-12-07 00:54

    You can do this

    $(document).bind('mousedown mouseup', function() {
        $('.finger').toggle();
    });
    

    Check working example at http://jsfiddle.net/2cSj4/2/

    0 讨论(0)
  • 2020-12-07 01:00

    Billy Moon, your code was almost working. You just have to use hide and show instead of css :

    $('#finger').click(function(e){
      evt = e || window.event;
    
      // make finger disappear
      $('#finger').hide(0);
    
      // get element at point of click
      starter = document.elementFromPoint(evt.clientX, evt.clientY);
    
      // send click to element at finger point
      $(starter).click();
    
      // bring back the finger
      $('#finger').show(0);
    });
    
    0 讨论(0)
  • 2020-12-07 01:06

    Check out this answer to on this post:

    https://stackoverflow.com/a/4839672/589909

    It seems to do what I understand what you want to achieve using a pure cross browser CSS approach.

    pointer-events:none; touch-action:none;

    0 讨论(0)
  • 2020-12-07 01:11

    This is untested - but is based on a working script of mine, so should be along the right lines. Basically, you have to make the layer that is in the way disappear for a moment, so you can use the elementFromPoint method and then make it come back.

    $('.selector').click(function(e){
        evt = e || window.event;
    
        // make finger disappear
        $('.finger').css({display:'none'});
    
        // get element at point of click
        starter = document.elementFromPoint(evt.clientX, evt.clientY);
    
        // send click to element at finger point
        $(starter).click();
    
        // bring back the finger
        $('.finger').css({display:''});
    });
    
    0 讨论(0)
提交回复
热议问题