我试图在此处使用材料UI的日期选择器日期悬停(单击任何文本输入以触发选择器,然后在一天中徘徊)时,试图复制效果从中心向外扩展。
我尝试从这里复制CSS,但是我只设法使相反的工作。请参阅:https://jsfiddle.net/2zkofa0x/3/
我的CSS:
span:hover {
color: #fff;
background: rgba(0, 151, 167, 0.5);
border-radius: 50%;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
}
有人知道我如何使彩色背景散布并从元素的中心填充(与我上面的相反)?
您可以尝试这样。它将悬停效果放在父级,因此命中目标始终存在。
此外,圆圈需要以0的比例开始,以便在过渡期间扩展到全尺寸。
html:
<div class='container'>
<div class='circle'>
</div>
<span>42</span>
</div>
CSS:
div.container {
position: relative;
height: 30px;
width: 30px;
}
div.container > div.circle {
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
width: 30px;
height: 30px;
transform: scale(0);
transition: all 450ms ease 0ms;
}
div.container:hover > div.circle {
background: rgba(0, 151, 167, .5);
border-radius: 50%;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
}
div.container span {
position: relative;
padding: 7px;
line-height: 30px;
}
div.container:hover span {
color: rgb(255, 255, 255);
}
https://jsfiddle.net/2zkofa0x/18/
使用 box-shadow
li { position: relative; display: inline-block; padding: 10px; }
li:before {
content: '';
height: 1px;
width: 1px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 0 0px #18b;
border-radius: 50%;
background: #18b;
transition: all .3s;
opacity: 0;
z-index: -1;
}
li:hover:before {
box-shadow: 0 0 0 15px #18b;
opacity: 1;
}
<ul>
<li>1</li>
<li>2</li>
</ul>
您可以尝试这样的事情。您也可以使用jQuery获得相同的效果。
/* Material style */
button {
height: 200px;
width: 200px;
border: none;
cursor: pointer;
color: white;
padding: 15px;
border-radius: 360px;
font-size: 22px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
background: #2196F3;
}
/* Ripple magic */
button{
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: 50%;
transform: scale(1, 1) translate(-50%);
transform-origin: 50% 50%;
}
@keyframes ripple {
0% {
transform: scale(0, 0);
opacity: 1;
}
20% {
transform: scale(25, 25);
opacity: 1;
}
100% {
opacity: 0;
transform: scale(40, 40);
}
}
button:focus:not(:active)::after {
animation: ripple 1s ease-out;
}
/* On Hover */
.ripple-button1{
position:relative;
width:200px;
height:200px;
background-color:#99C;
color:#FFF;
border-radius:360px;
text-decoration:none;
text-align:center;
vertical-align:middle;
display:table-cell;
box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
}
.wave1{
position:absolute;
width:200px;
height:200px;
background-color:#FFF;
top:0;
left:0;
transform: scale(0);
opacity:0.5;
border-radius:300px;
}
.ripple-button1:hover > .wave1{
animation: ripple-in1 2s;
}
@keyframes ripple-in1 {
0% {transform: scale(0);}
20%{transform: scale(1);opacity:0.3;}
100%{transform: scale(1);opacity:0;}
}
<h3>Ripple on Click</h3>
<button>Click !</button>
<h3>Ripple on Hover</h3>
<a href="#" class="ripple-button1"><div class="wave1"></div>Hover !</a>
我正在寻找相同的内容。谢谢您的提高。尽管您已经选择了一个答案,但我将分享我的黑客,看起来与引用页面上的hack相似。
div {
margin: 25px;
height: 100px;
width: 100px;
text-align: center; //Fix the element to center
}
span {
width: 50px;
height: 50px;
padding: 5px;
border-radius: 50%;
}
span:hover {
color: #fff;
background: rgba(0, 151, 167, 0.5);
padding: 15px; //Transform padding, width and height instead of border-radius
width: 20px;
height: 20px;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 1ms;
}
<div>
<span>42</span>
</div>