【问题标题】:Ripple effect is not working on Mac browsers涟漪效应在 Mac 浏览器上不起作用
【发布时间】:2018-03-25 12:12:03
【问题描述】:

我正在使用引导库中的涟漪效应,但是我遇到了一个以前从未见过的奇怪问题。在 Chrome (Mac) 上效果对我来说效果很好。但是,在 safari 和 Firefox(59.0.1,Mac)上,效果不起作用。

奇怪的是,该效果适用于 Windows 版 FireFox、IE 和 Chrome 版。

我不确定出了什么问题,因为它具有这些浏览器的所有 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>

【问题讨论】:

  • 我找不到任何用于波纹效果的 CSS 规范。它在哪里?

标签: html css


【解决方案1】:

我认为问题在于在 OS X 中单击 Safari 和 Firefox 中的按钮不会导致按钮成为焦点,因此您的动画不会被触发:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus

我测试了你的代码,在 Safari 中添加了一些 jQuery 以强制在按钮单击时保持焦点状态,它对我有用:

$('button').on('click', function() {
  $(this).focus();
});

https://jsfiddle.net/u3qde8hx/28/

另外,如果您将按钮替换为锚标记,您似乎可以在 Firefox(至少在 59.0.1 上)和 Safari(10.1)中在 OS X 上完成此操作,但您必须确保设置 tabindex .

https://jsfiddle.net/u3qde8hx/36/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2019-09-15
    相关资源
    最近更新 更多