简体   繁体   English

HTML链接未在某些点击中注册

[英]Html link not registering on some clicks

I tried to create a fancy button. 我试图创建一个精美的按钮。 Problem that when it is clicked just between text and bottom edge of the button click event do not fire. 问题是仅在文本和按钮click事件的底部边缘之间click不会触发。 Here is jsbin . 这是jsbin

Seems to be that problem in this code: 在这段代码中似乎就是这个问题:

.button:active {
  top:2px;
  box-shadow:0 2px #36c
}

But i need this "push" effect. 但是我需要这种“推动”效果。 So how to save the effect and get click event back? 那么,如何保存效果并获得点击事件呢?

Don't use box-shadow , use border-bottom , like so: 不要使用box-shadow ,使用border-bottom ,就像这样:

.button {
    border-bottom: 4px solid #000;
}

.button:active {
    border-bottom: 2px solid #000;
}

Demo: http://jsbin.com/IGUReWO/1/ 演示: http//jsbin.com/IGUReWO/1/

that's because the click event fires on mouseup where as mousedown obviously gets fired on mousedown. 这是因为click事件在mouseup上触发,而mousedown显然在mousedown上触发。 I only could reproduce the behaviour you described, if i click the button and release the mouse outside of it. 如果我单击按钮并在其外部释放鼠标,则只能重现您描述的行为。

If you want the push effect, you could attach the mousedown event instead of the click event and delay it for a few ms, for instance: 如果需要推入效果,则可以附加mousedown事件而不是click事件,并将其延迟几毫秒,例如:

$('.button').on('mousedown', function() {
  window.setTimeout(function() {
    var val = parseInt($('.mousedown span').html(), 10);
    val++;
    $('.mousedown span').text(val);
    return false;
  }, 200);
});

I hope i could help, Cheers 希望我能帮上忙,干杯

replace 更换

box-shadow: 0 4px black;

with

border-bottom: 4px solid black;

and

box-shadow:0 2px black;

with

border-bottom: 2px solid black;

You can't click on a box shadow, but you can click on a border. 您不能单击方框阴影,但是可以单击边框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM