CSS实现8个奖品的抽奖盘是很有趣的一个挑战。我们需要使用CSS3的transform和transition属性,同时结合伪类元素实现奖品的分布和旋转动画。
.plate { position: relative; width: 400px; height: 400px; border-radius: 50%; background: #f2f2f2; margin: 0 auto; transform-style: preserve-3d; } .plate:hover .item { transform: translateY(-50%) rotateX(720deg) rotateY(360deg); } .item { position: absolute; width: 100px; height: 100px; background: #d0d0d0; border-radius: 50%; transform-origin: 50% -200px; transition: transform 5s ease; } .item:first-child { top: 0px; left: 150px; } .item:nth-child(2) { top: 80px; left: 80px; } .item:nth-child(3) { top: 150px; left: 0px; } .item:nth-child(4) { top: 150px; right: 0px; } .item:nth-child(5) { top: 80px; right: 80px; } .item:nth-child(6) { bottom: 0px; left: 150px; } .item:nth-child(7) { bottom: 150px; left: 0px; } .item:last-child { bottom: 150px; right: 0px; } .item:before { content: ""; position: absolute; top: 50%; left: 50%; width: 60px; height: 60px; background: #fff; border-radius: 50%; transform: translate(-50%,-50%); z-index: 2; }
在这段代码中,我们使用了.center样式来居中盘子,同时设置了盘子的宽度、高度、边框半径和背景颜色。
我们使用了:hover伪类来添加鼠标悬停时的动画效果。在.item样式中,我们设置了每个奖品的尺寸、背景颜色、圆形边框半径以及通过transform-origin属性设置了奖品的旋转中心。
接下来,我们为每个奖品设置了具体的位置,同时在最后一个奖品前添加了一个伪元素来模拟奖品的图标。
通过使用CSS3的transform属性,我们可以设置奖品的旋转动画,同时添加了transition属性来使动画效果更加平滑。
这样,一个简单的CSS抽奖盘就可以实现了!可以根据实际需要来增加或减少奖品,同时调整奖品的位置和动画效果。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。