CSS动画不必要的效果

时间:2018-10-16 14:52:53

标签: html css animation css-transitions

我有一个大圆圈,里面有3个小圆圈。现在,我希望每当我将鼠标悬停在大圆圈上时,这些较小的圆圈就会移动并更改其宽度/高度,但是每当我尝试执行此操作时,都会产生不想要的效果,从而导致很多问题。有人可以指导我解决问题吗?

.wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

.wrapper .button {
    width : 150px;
    height: 150px;
    border-radius: 50% ;
    background-color: #FFC5B4 ;      
    text-align: center ;
    line-height: 150px; 
}

.button .circle {
    display: inline-block ;
    width: 20px ;
    height: 20px;
    border-radius: 50% ;
    background-color: crimson ;
    transition: all 3s ease-in-out ;
}

.button:hover .circle.num1 { 
    transform: translate(-10em,-10em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num2 { 
    transform: translateY(-15em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num3 { 
    transform: translate(10em,-10em) ;
    width: 100px ;
    height: 100px;
}
<body>
    <div class="wrapper">
        <div class="button">
            <span class="circle num1"></span>
            <span class="circle num2"></span>
            <span class="circle num3"></span>
        </div>
    </div>
</body>

1 个答案:

答案 0 :(得分:2)

您将需要使用position:absolute绘制圆圈,并使用margin将其放置在正确的位置。

绝对位置将删除圆的边界。

请参见下面的代码段-

.wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

.wrapper .button {
    width : 150px;
    height: 150px;
    border-radius: 50% ;
    background-color: #FFC5B4 ;      
    text-align: center ;
    line-height: 150px; 
}

.button .circle {
    display: inline-block ;
    width: 20px ;
    height: 20px;
    border-radius: 50% ;
    background-color: crimson ;
    transition: all 3s ease-in-out;
    position:absolute;
    margin:auto;
    left:0;
    right:0;
    top:0;
    bottom:0;
}
span.circle.num1{
  margin-left:40px;
}
span.circle.num3{
  margin-right:40px;
}
.button:hover .circle.num1 { 
    transform: translate(-10em,-10em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num2 { 
    transform: translateY(-15em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num3 { 
    transform: translate(10em,-10em) ;
    width: 100px ;
    height: 100px;
}
<body>
    <div class="wrapper">
        <div class="button">
            <span class="circle num1"></span>
            <span class="circle num2"></span>
            <span class="circle num3"></span>
        </div>
    </div>
</body>