弹珠css3,使用CSS3实现的弹球小动画

CSS

语言:

CSSSCSS

确定

body {

background: #111;

width: 330px;

height: 200px;

position: absolute;

top: 50%;

left: 50%;

margin-left: -165px;

margin-top: -135px;

}

span {

width: 70px;

height: 70px;

animation: rotation 1s ease-out infinite;

-webkit-animation: rotation 1s ease-out infinite;

position: absolute;

transform-style: preserve-3d;

-webkit-transform-style: preserve-3d;

left: 0;

bottom: 0;

}

.circle {

border: 5px solid #31beff;

width: 70px;

height: 70px;

border-radius: 150px;

box-sizing: border-box;

animation: bounce 1s infinite;

-webkit-animation: bounce 1s infinite;

position: absolute;

z-index: 2;

top: 0;

}

.face {

width: 100%;

height: 100%;

position: absolute;

border: 5px solid #dc2114;

box-sizing: border-box;

}

.front {

-webkit-transform: translate3d(0, 0, 35px);

transform: translate3d(0, 0, 35px);

}

.top {

-webkit-transform: rotateX(90deg) translate3d(0, 0, 35px);

transform: rotateX(90deg) translate3d(0, 0, 35px);

}

.one {

animation-delay: 0s;

-webkit-animation-delay: 0s;

}

.two {

animation-delay: -1.2s;

-webkit-animation-delay: -1.2s

}

.three {

animation-delay: -1.6s;

-webkit-animation-delay: -1.6s;

}

figure {

width: 70px;

height: 200px;

position: relative;

display: inline-block;

vertical-align: top;

margin: 20px;

}

@keyframes rotation {

0% {

transform: rotateX(0deg)

}

60% {

transform: rotateX(0deg)

}

100% {

transform: rotateX(-90deg)

}

}

@-webkit-keyframes rotation {

0% {

-webkit-transform: rotateX(0deg)

}

60% {

-webkit-transform: rotateX(0deg)

}

100% {

-webkit-transform: rotateX(-90deg)

}

}

@keyframes bounce {

0% {

top: 0;

}

10% {

top: 5px;

}

20% {

width: 60px;

height: 80px;

margin-left: 5px;

}

40% {

top: 67px;

width: 80px;

height: 65px;

margin-left: -5px;

}

65% {

top: 0;

}

70% {

top: -5px;

}

}

@-webkit-keyframes bounce {

0% {

top: 0;

}

10% {

top: 5px;

}

20% {

width: 60px;

height: 80px;

margin-left: 5px;

}

40% {

top: 67px;

width: 80px;

height: 65px;

margin-left: -5px;

}

65% {

top: 0;

}

70% {

top: -5px;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 Java 编程语言来实现一个简单的弹球小游戏。以下是一个示例代码: ```java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class BallGame extends JPanel implements ActionListener { private int ballX = 0; private int ballY = 0; private int ballSpeedX = 1; private int ballSpeedY = 1; public BallGame() { Timer timer = new Timer(5, this); timer.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.RED); g.fillOval(ballX, ballY, 30, 30); } public void actionPerformed(ActionEvent e) { if (ballX < 0 || ballX > getWidth() - 30) { ballSpeedX = -ballSpeedX; } if (ballY < 0 || ballY > getHeight() - 30) { ballSpeedY = -ballSpeedY; } ballX += ballSpeedX; ballY += ballSpeedY; repaint(); } public static void main(String[] args) { JFrame frame = new JFrame("Ball Game"); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BallGame game = new BallGame(); frame.add(game); frame.setVisible(true); } } ``` 以上代码创建了一个 `BallGame` 类,继承自 `JPanel` 并实现了 `ActionListener` 接口。在 `paint` 方法中,我们绘制了一个红色的圆。在 `actionPerformed` 方法中,我们更新的位置,并重新绘制。 在 `main` 方法中,我们创建了一个 `JFrame` 并将 `BallGame` 对象添加到其中,然后显示窗口。 这个简单的例子实现了一个可以在窗口中上下左右移动的圆。你可以根据自己的需求添加更多的功能,比如碰撞检测、得分等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值