【问题标题】:CSS Button responding with a "beacon" as a click eventCSS Button 以“信标”作为点击事件响应
【发布时间】:2017-04-02 13:35:19
【问题描述】:

我想创建一个与此页面上的按钮类似的事件:

https://bootswatch.com/paper/#buttons

如您所见,点击时按钮内部会出现较暗的颜色。

这些“事件”叫什么?是否需要使用 jQuery 来完成,或者仅使用 CSS 是否可行?我只能为此想出一个名称,那只是一个单击事件信标按钮,但是在谷歌搜索之后,我似乎没有找到任何结果。

【问题讨论】:

  • 都是 CSS。他们正在使用由元素的:active 状态触发的转换。使用开发人员工具并检查有问题的元素。对于 Chrome,在Styles 选项卡下有一个:hov 选项卡,可让您将各种状态应用于按钮。将:active 应用于按钮。检查按钮的样式和伪元素的样式。

标签: jquery css events button twitter-bootstrap-3


【解决方案1】:

您只能通过使用 css 来实现这一点。无需使用 jquery。您必须为 .button、.button:after 和 .button:active:after 事件编写一个 CSS(假设该按钮是您的类名或按钮)。

这是我尝试过的css

<!DOCTYPE html>
<html>
<head>
<style>
.button {
text-transform: uppercase;
    border: none;
    -webkit-box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
    box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
    -webkit-transition: all 0.4s;
    -o-transition: all 0.4s;
    transition: all 0.4s;
    position: relative;
   display: inline-block;
    margin-bottom: 0;
    font-weight: normal;
    text-align: center;
    vertical-align: middle;
    /*-ms-touch-action: manipulation;*/
    /*touch-action: manipulation;*/
    cursor: pointer;
    background-image: none;
    border: 1px solid transparent;
    white-space: nowrap;
    padding: 6px 16px;
    font-size: 13px;
    line-height: 1.846;
    border-radius: 3px;
    
}

.button:after {
   content: "";
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-image: -webkit-radial-gradient(circle, #000000 10%, transparent 10.01%);
    background-image: -o-radial-gradient(circle, #000000 10%, transparent 10.01%);
    background-image: radial-gradient(circle, #000000 10%, transparent 10.01%);
    background-repeat: no-repeat;
    -webkit-background-size: 1000% 1000%;
    background-size: 1000% 1000%;
    background-position: 50%;
    opacity: 0;
    pointer-events: none;
    -webkit-transition: background .5s, opacity 1s;
    -o-transition: background .5s, opacity 1s;
    transition: background .5s, opacity 1s;
}


.button:active:after {
    -webkit-background-size: 0% 0%;
    background-size: 0% 0%;
    opacity: .2;
    -webkit-transition: 0s;
    -o-transition: 0s;
    transition: 0s;
}
</style>
</head>
<body>

<h2>Animated Button - Ripple Effect</h2>

<button class="button">Click Me</button>

</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多