使用css制作一个手机充电黏黏球效果

要制作一个手机充电黏黏球效果,我们需要创建一个动画,使“黏黏球”能够“吸附”到手机或充电器上。以下是一个简单的实现方法:

  1. HTML结构
<div class="phone">
    <div class="charging-port"></div>
</div>
<div class="sticky-ball"></div>
  1. CSS样式
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f5f5f5;
}

.phone {
    width: 100px;
    height: 200px;
    background-color: #333;
    position: relative;
    margin-right: 50px;
}

.charging-port {
    width: 10px;
    height: 10px;
    background-color: yellow;
    position: absolute;
    bottom: 10px;
    left: 45px;
}

.sticky-ball {
    width: 50px;
    height: 50px;
    background-color: red;
    border-radius: 50%;
    position: relative;
    animation: stickyAnimation 2s infinite;
}

@keyframes stickyAnimation {
    0% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(120px);
    }
    100% {
        transform: translateX(0);
    }
}

这个示例中,.phone代表手机,.charging-port代表充电口,而.sticky-ball代表黏黏球。我们为.sticky-ball添加了一个动画stickyAnimation,使其可以在手机和初始位置之间移动,从而产生“吸附”效果。

你可以根据需要调整动画的细节、速度、距离等来达到你想要的效果。此外,为了更真实的效果,你还可以为黏黏球添加更多的动画细节,如弹跳、旋转等。

注意:这只是一个非常基础的示例,你可以根据具体需求进行扩展和优化。

posted @ 2024-12-18 06:02  王铁柱6  阅读(23)  评论(0)    收藏  举报