简体   繁体   English

轻触手机后,移除按钮悬停效果吗?

[英]Remove button hover effect after tap on mobile?

I have a basic JS flashcard game I made. 我有一个基本的JS抽认卡游戏。 There are 12 "answer buttons" for a user to choose from. 有12个“答案按钮”供用户选择。

On mobile, the answer buttons retain the hover effect/focus(?) after being tapped (this does not happen on desktop, any browser). 在移动设备上,点按后,接听按钮将保持悬停效果/ focus(?)(在台式机和任何浏览器上均不会发生)。 This is very confusing from a user standpoint as it can appear as though the app/flashcard is stuck or not updating. 从用户的角度来看,这非常令人困惑,因为它看起来好像是应用程序/闪存卡被卡住或未更新。

I'm using Bootstrap 4.1. 我正在使用Bootstrap 4.1。

Here is my button code, but there's nothing unusual about it: 这是我的按钮代码,但是没有什么不寻常的地方:

<button type="button" id="E" class="btn btn-lg btn-info ansBtn" value="E">Answer</button>

I've looked at similar questions (but they were regarding bootstrap 3), which suggested using either an anchor tag instead of the button tag, but that didn't work (with and without the href attr). 我看过类似的问题(但它们与引导3有关),建议使用锚标签而不是按钮标签,但这是行不通的(有和没有href属性)。

I've also tried another suggestion to include this bit of jQuery, but it doesn't seem to work with 4.1 either. 我还尝试了另一种建议来包括这部分jQuery,但它似乎也不适用于4.1。 I've used button ID, and other classnames, but it has not worked. 我使用了按钮ID和其他类名,但是没有用。

 $(".btn").mouseup(function(){
     $(this).blur();
 });

Suggestions? 建议? Thanks! 谢谢!

Update 更新

So here is the latest. 所以这是最新的。 I've added the below CSS. 我添加了以下CSS。 This give mobile users the experience I want (a "flash" of background-color/border-color change only on click/tap). 这给移动用户带来了我想要的体验(仅在单击/点击时背景颜色/边框颜色会“闪烁”)。 HOWEVER, now when using my macbook pro and TAPPING with my trackpad, the effect does not occur! 但是,现在将Macbook Pro和触控板一起使用时,效果不会发生! It works when I click with the trackpad, but not tap with the track pad. 当我用触控板单击但不用触控板点击时,它可以工作。 :( :(

.btn.btn-info {
    background-color: #17a2b8
} 

.btn-info:not(:disabled):not(.disabled).active,
.btn-info:not(:disabled):not(.disabled):active, 
.show > .btn-info.dropdown-toggle {
     background-color: #117a8b;
     border-color: #10707f;
 }

You can always add a .setTimeout() function on the objects .onHover() or .onClick() event. 您始终可以在对象.onHover().onClick()事件上添加.setTimeout()函数。 This will allow your flashcard to be flipped/blurred after a certain amount of time. 这将使您的抽认卡在一定时间后翻转/模糊。 Alternatively, you can simply change the functionality of your application for mobile browsers and make it so you have to click to see the answer. 另外,您只需更改应用程序的功能以用于移动浏览器,然后进行更改,因此您必须单击以查看答案。 You should also look into the .focus() method and possibly try to change focus to another element on the page. 您还应该研究.focus()方法,并可能尝试将焦点更改为页面上的另一个元素。 If none of this is working, it is probably some quirk with jQuery. 如果以上方法均无效,则可能与jQuery有关。 I would suggest trying to selct the element this way: 我建议尝试以这种方式选择元素:

document.querySelector(".btn").onmouseup = function(){ this.blur(); });

or: 要么:

document.querySelector(".btn").onmouseup = function(){ document.body.focus(); });

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

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