php页面如何加入滚动广告,前端页面内实现左右摇摆广告

这次给大家带来前端页面内实现左右摇摆广告,前端页面内实现左右摇摆广告的注意事项有哪些,下面就是实战案例,一起来看一下。

代码解读

定义 dom,容器中包含公告牌、挂公告牌的细绳和固定绳子的 3 个图钉:

THANKS

居中显示:html, body {

width: 100%;

height: 100%;

display: flex;

align-items: center;

justify-content: center;

background: radial-gradient(circle at center 60%, white, sandybrown);

}

定义公告牌的整体尺寸:.signboard {

width: 400px;

height: 300px;

}

设置木板的样式:.signboard {

position: relative;

}

.sign {

width: 100%;

height: 200px;

background: burlywood;

border-radius: 15px;

position: absolute;

bottom: 0;

}

设置有雕刻效果的文字样式:.sign {

color: saddlebrown;

font-family: sans-serif;

font-weight: bold;

text-align: center;

line-height: 200px;

text-shadow: 0 2px 0 rgba(255, 255, 255, 0.3),

0 -2px 0 rgba(0, 0, 0, 0.7);

}

画出细绳:.strings {

width: 150px;

height: 150px;

border: 5px solid brown;

position: absolute;

border-right: none;

border-bottom: none;

transform: rotate(45deg);

top: 38px;

left: 122px;

}

画出细绳顶部的图钉:.pin {

width: 25px;

height: 25px;

border-radius: 50%;

position: absolute;

}

.pin.top {

background: gray;

left: 187px;

}

画出木板上左右两侧的图钉:.pin.left,

.pin.right {

background: brown;

top: 110px;

box-shadow: 0 2px 0 rgba(255, 255, 255, 0.3);

}

.pin.left {

left: 80px;

}

.pin.right {

right: 80px;

}

最后,让告示牌晃动起来:

(此处已按 小蕾蕾 的建议修改为以顶部图钉作为旋转轴,比最初的效果要好).signboard {

animation: swing 1.5s ease-in-out infinite alternate;

transform-origin: 200px 13px;

}

@keyframes swing {

from {

transform: rotate(10deg);

}

to {

transform: rotate(-10deg);

}

}

大功告成!

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的JavaFX代码示例,可以实现汽车雨刷不同挡位左右摇摆: ```java import javafx.animation.*; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Line; import javafx.stage.Stage; import javafx.util.Duration; public class CarWiper extends Application { private final static int WIDTH = 400; private final static int HEIGHT = 400; private Line leftWiper; private Line rightWiper; @Override public void start(Stage primaryStage) throws Exception { Pane root = new Pane(); // 左雨刷 leftWiper = new Line(0, HEIGHT / 2, 0, HEIGHT / 2 - 30); leftWiper.setStrokeWidth(3); leftWiper.setStroke(Color.BLACK); root.getChildren().add(leftWiper); // 右雨刷 rightWiper = new Line(WIDTH, HEIGHT / 2, WIDTH, HEIGHT / 2 - 30); rightWiper.setStrokeWidth(3); rightWiper.setStroke(Color.BLACK); root.getChildren().add(rightWiper); Scene scene = new Scene(root, WIDTH, HEIGHT); primaryStage.setScene(scene); primaryStage.show(); // 模拟不同挡位 int speed = 1; // 默认挡位 switch (speed) { case 1: // 左右交替 Timeline timeline = new Timeline( new KeyFrame(Duration.ZERO, new KeyValue(leftWiper.startXProperty(), 0), new KeyValue(leftWiper.startYProperty(), HEIGHT / 2), new KeyValue(leftWiper.endXProperty(), 0), new KeyValue(leftWiper.endYProperty(), HEIGHT / 2 - 30), new KeyValue(rightWiper.startXProperty(), WIDTH), new KeyValue(rightWiper.startYProperty(), HEIGHT / 2), new KeyValue(rightWiper.endXProperty(), WIDTH), new KeyValue(rightWiper.endYProperty(), HEIGHT / 2 - 30)), new KeyFrame(Duration.seconds(1), new KeyValue(leftWiper.startXProperty(), 0), new KeyValue(leftWiper.startYProperty(), HEIGHT / 2 - 30), new KeyValue(leftWiper.endXProperty(), 0), new KeyValue(leftWiper.endYProperty(), HEIGHT / 2), new KeyValue(rightWiper.startXProperty(), WIDTH), new KeyValue(rightWiper.startYProperty(), HEIGHT / 2 - 30), new KeyValue(rightWiper.endXProperty(), WIDTH), new KeyValue(rightWiper.endYProperty(), HEIGHT / 2)) ); timeline.setCycleCount(Timeline.INDEFINITE); timeline.play(); break; case 2: // 左右同时 ParallelTransition parallelTransition = new ParallelTransition( createWiperAnimation(leftWiper), createWiperAnimation(rightWiper) ); parallelTransition.setCycleCount(Timeline.INDEFINITE); parallelTransition.play(); break; case 3: // 顺时针 RotateTransition leftRotate = new RotateTransition(Duration.seconds(1), leftWiper); leftRotate.setByAngle(360); leftRotate.setCycleCount(Timeline.INDEFINITE); leftRotate.play(); RotateTransition rightRotate = new RotateTransition(Duration.seconds(1), rightWiper); rightRotate.setByAngle(360); rightRotate.setCycleCount(Timeline.INDEFINITE); rightRotate.play(); break; default: break; } } private Animation createWiperAnimation(Line wiper) { RotateTransition rotate1 = new RotateTransition(Duration.seconds(0.5), wiper); rotate1.setByAngle(30); RotateTransition rotate2 = new RotateTransition(Duration.seconds(0.5), wiper); rotate2.setByAngle(-30); return new SequentialTransition(rotate1, rotate2); } } ``` 在上述代码中,我们首先创建了一个`Pane`作为根节点,并在其中添加了两条线段,分别表示左右雨刷。接着,我们根据不同挡位的要求,使用不同的动画来实现左右摇摆的效果: - 挡位1:左右交替摇摆 - 使用`Timeline`来交替执行左右雨刷的动画 - 挡位2:左右同时摇摆 - 使用`ParallelTransition`来同时执行左右雨刷的动画 - `createWiperAnimation()`方法用于创建单个雨刷的摇摆动画 - 挡位3:顺时针摇摆 - 使用`RotateTransition`来对左右雨刷进行旋转 最后,我们将不同挡位的动画循环执行,以实现汽车雨刷的效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值