我正在使用来自 Bootstrap 库的涟漪效应,但是我遇到了一个以前从未见过的奇怪问题。这种效果在 Chrome (Mac) 上对我来说效果很好。但是,在 safari 和 Firefox(59.0.1,Mac)上效果不起作用。
奇怪的是,该效果适用于 FireFox for windows、IE 和 Chrome for windows。
我不确定哪里出了问题,因为它具有适用于这些浏览器的所有 Web 工具包属性。
试一试:https://jsfiddle.net/u3qde8hx/2/
* { box-sizing:border-box; }
button {
border: none;
cursor: pointer;
color: black;
width: 130px;
padding: 10px;
border-radius: 2px;
font-size: 19px;
background: royalblue;
position: relative;
overflow: hidden;
}
button:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 5px;
height: 5px;
background: rgba(255, 255, 255, .5);
opacity: 0;
border-radius: 100%;
-webkit-transform: scale(1, 1) translate(-50%);
-moz-transform: scale(1, 1) translate(-50%);
-ms-transform: scale(1, 1) translate(-50%);
-o-transform: scale(1, 1) translate(-50%);
transform: scale(1, 1) translate(-50%);
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
}
@keyframes ripple {
0% {
-webkit-transform: scale(0, 0);
-moz-transform: scale(0, 0);
-ms-transform: scale(0, 0);
-o-transform: scale(0, 0);
transform: scale(0, 0);
opacity: 1;
}
20% {
-webkit-transform: scale(25, 25);
-moz-transform: scale(25, 25);
-ms-transform: scale(25, 25);
-o-transform: scale(25, 25);
transform: scale(25, 25);
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: scale(40, 40);
-moz-transform: scale(40, 40);
-ms-transform: scale(40, 40);
-o-transform: scale(40, 40);
transform: scale(40, 40);
}
}
button:focus:not(:active)::after {
-webkit-animation: ripple 1s ease-out;
-moz-animation: ripple 1s ease-out;
-o-animation: ripple 1s ease-out;
animation: ripple 1s ease-out;
}
button:focus{
outline: none;
}
<p>If you are using FireFox or Safari (Mac versions), this ripple effect will not work for you. It works on PC browsers and Chrome for Mac.</p>
<button>Ripple</button>
最佳答案
我认为问题在于在 Safari 和 Firefox 中单击 OS X 中的按钮不会导致按钮成为焦点,因此您的动画不会被触发:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
我测试了您的代码,添加了这段 jQuery 以在 Safari 中强制单击按钮时的焦点状态,它对我有用:
$('button').on('click', function() {
$(this).focus();
});
https://jsfiddle.net/u3qde8hx/28/
或者,如果您将按钮替换为 anchor 标记,您似乎可以在 Firefox(至少在 59.0.1)和 OS X 上的 Safari(10.1)中完成此操作,但您必须确保设置 tabindex .
关于html - 涟漪效应在 Mac 浏览器上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49395464/