Use javascript to click on a pseudo-element?

前端 未结 5 1509
栀梦
栀梦 2020-12-03 14:37

I\'m wondering how to enable the clicking on a :before pseudo-element (the orange part of the div on the JSfiddle I link to below). I\'ve read that since pseudo

5条回答
  •  清歌不尽
    2020-12-03 14:58

    If you know where the circle "should" be, you can use trigonometry to see if the click is within the circle: http://jsfiddle.net/Vv6Eb/19/

    $("div").click(function(e){
        var $me = $(this),
            width = $me.outerWidth(),
            height = $me.outerHeight(),
            top = $me.position().top,
            left = $me.position().left;
    
        var len = Math.sqrt(Math.pow(width - e.offsetX, 2) + Math.pow(e.offsetY, 2));
    
        if (len < 10)
            alert('ding');
    });​
    

提交回复
热议问题