gpt4 book ai didi

jquery - 涟漪效应继续越过圆 Angular (尤其是圆形按钮)

转载 作者:太空宇宙 更新时间:2023-11-04 10:37:36 33 4
gpt4 key购买 nike

我正在尝试在 CSS、HTML 和 JS 中制作具有波纹效果的 Material 按钮,但波纹效果一直在像这样覆盖按钮:
-->This is a GIF of what happens
如何消除边界外的涟漪?
我尝试使用父 div 来掩盖外面的波纹,但它也掩盖了阴影和按钮的一部分。

这是一个片段:

$(".buttons").click(function() {
var div = $("<div/>");
var offset = $(this).offset();
var posx = event.pageX - offset.left;
var posy = event.pageY - offset.top;
div.addClass("ripple");
div.css({
"width": $(this).width,
"height": $(this).height,
"top": posy,
"left": posx,
"background": $(this).data("ripple_color"),
}).appendTo($(this));
setTimeout(function() {
div.remove();
}, 1500);
});
//creates a div, and gets the mouse positions. then the div gets a css class and gets inserted into the button that's clicked on. after 1.5 seconds, it is removed.
* {
font-family: Roboto;
}


.buttons {
background-color: transparent;
border: none;
position: absolute;
text-align: center;
color: white;
transition-timing-function: linear;
cursor: pointer;
display: inline-block;
font-size: 30px;
font-weight: 500;
overflow: hidden;
}
.buttons:focus {
outline: none;
}

/*raised button (the blue one)*/
.raised_button {
background-color: #3d81f6;
box-shadow: 0px 4px 4px #666666;
width: 172px;
line-height: 72px;
border-radius: 8px;
transition: background-color 0.2s, box-shadow 0.2s, margin-top 0.2s;
}
.raised_button:hover {
box-shadow: 0px 10px 24px #666666;
margin-top: -10px;
background-color: #326ec9;
}
.raised_button:focus {
box-shadow: 0px 4px 18px #666666;
margin-top: -4px;
background-color: #326ec9;
}

/*FAB (the round red button)*/
.fab {
height: 100px;
background-color: #dc422f;
transition-timing-function: linear;
box-shadow: 0px 10px 16px #666666;
width: 100px;
border-radius: 100%;
transition: background-color 0.2s, box-shadow 0.2s, margin-top 0.2s, transform 0.2s;
}
.fab:hover {
box-shadow: 0px 24px 26px #666666;
margin-top: -10px;
background-color: #c43a2b;
}

/*flat button (the green one without shadows)*/
.flat_button {
color: #4CAF50;
padding-left: 24px;
padding-right: 24px;
padding-top: 16px;
padding-bottom: 16px;
border-radius: 8px;
transition: background-color 0.2s linear;
}
.flat_button:hover {
background-color: rgba(200, 230, 201, 0.7);
}
.flat_button:focus {
background-color: #E8F5E9;
}

/*ripple div that expands and creates the effect*/
.ripple {
position: absolute;
border-radius: 100%;
width: 30px;
height: 30px;
background: white;
animation: ripple_animation 1.5s;
}
/*ripple animation*/
@keyframes ripple_animation {
from {
transform: scale(1);
opacity: 0.4;
}
to {
transform: scale(100);
opacity: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300italic,300,400italic,500,500italic,700,700italic" rel="stylesheet" type="text/css">
<button class="draggable buttons raised_button">RAISED</button>
<button class="draggable buttons fab">FAB</button>
<button class="draggable buttons flat_button">FLAT</button>
<script>
$(".draggable").draggable({
cancel: false
});
</script>


相关代码如下:
HTML:

<button class="draggable buttons raised_button">RAISED</button>
<button class="buttons fab">FAB</button>
<button class="draggable buttons flat_button">FLAT</button>

CSS:

.ripple {
position: absolute;
border-radius: 100%;
width: 30px;
height: 30px;
background: white;
animation: ripple_animation 1.5s;
}

@keyframes ripple_animation {
from {
transform: scale(1);
opacity: 0.4;
}
to {
transform: scale(100);
opacity: 0;
}
}

JS:

$(".buttons").click(function() {
var div = $("<div/>");
var offset = $(this).offset();
var posx = event.pageX - offset.left;
var posy = event.pageY - offset.top;
div.addClass("ripple");
div.css({
"width": $(this).width,
"height": $(this).height,
"top": posy,
"left": posx,
"background": $(this).data("ripple_color"),
}).appendTo($(this));
setTimeout(function() {
div.remove();
}, 1500);
});

最佳答案

Google Material Design 有一个解决方案。将以下 CSS 属性添加到您的按钮:

transform: translate3d(0, 0, 0);

问题已解决。

关于jquery - 涟漪效应继续越过圆 Angular (尤其是圆形按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36049303/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com