Angular水平文本走马灯(无需外部库)
创始人
2024-10-29 14:01:39
0

下面是一个使用Angular实现水平文本走马灯的示例代码:

  1. 在组件的HTML模板中,使用ngFor指令循环遍历要显示的文本数组,并为每个文本项应用一个动画效果:
{{ text }}
  1. 在组件的CSS样式中定义走马灯容器和内容的样式,并为内容应用动画效果:
.marquee {
  width: 100%;
  overflow: hidden;
}

.marquee-content {
  display: inline-block;
  white-space: nowrap;
  padding: 10px;
}

@keyframes marquee-animation {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

.marquee-content {
  animation: marquee-animation 10s linear infinite;
}
  1. 在组件的TypeScript代码中定义文本数组并实现动画触发条件:
import { Component } from '@angular/core';
import { trigger, transition, animate, style } from '@angular/animations';

@Component({
  selector: 'app-marquee',
  templateUrl: './marquee.component.html',
  styleUrls: ['./marquee.component.css'],
  animations: [
    trigger('move', [
      transition(':enter', [
        style({ transform: 'translateX(100%)' }),
        animate('10s linear')
      ])
    ])
  ]
})
export class MarqueeComponent {
  texts = ['Text 1', 'Text 2', 'Text 3'];
}

请确保在使用该示例代码之前已在项目中安装了@angular/animations模块。

相关内容

热门资讯

透视插件!wpk模拟器是什么(... 透视插件!wpk模拟器是什么(透视)开挂辅助方法(真是是有挂)-哔哩哔哩1、游戏颠覆性的策略玩法,独...
透视科技!wepoker俱乐部... 透视科技!wepoker俱乐部辅助器,拱趴大菠萝十三水辅助,指南教程(本来存在有挂)-哔哩哔哩拱趴大...
透视存在!aapoker能控制... 透视存在!aapoker能控制牌吗,微信小程序辅助器免费,其实是真的挂(专业技巧教程)-哔哩哔哩1、...
透视规律!wepoker私人局... 透视规律!wepoker私人局俱乐部怎么进(透视)开挂辅助工具(原来真的是有挂)-哔哩哔哩;1、we...
透视脚本!wepoker正确养... 透视脚本!wepoker正确养号方法,德普之星透视辅助软件是真的吗,窍门教程(竟然存在有挂)-哔哩哔...
透视好牌!wepoker高级辅... 透视好牌!wepoker高级辅助,789大菠萝插件功能,原来真的是有挂(专业解说技巧)-哔哩哔哩1)...
透视安卓版本!wpk德州局透视... 透视安卓版本!wpk德州局透视(透视)开挂辅助app(确实有挂)-哔哩哔哩1)wpk德州局透视辅助挂...
透视真的!hhpoker脚本下... 透视真的!hhpoker脚本下载,hh poker软件,手段教程(确实真的是有挂)-哔哩哔哩1、hh...
透视私人局!如何下载wepok... 透视私人局!如何下载wepoker安装包,手游挂机辅助免费版,好像真的有挂(必备介绍教程)-哔哩哔哩...
透视小程序!aapoker辅助... 透视小程序!aapoker辅助工具安全吗(透视)开挂辅助插件(本来是真的挂)-哔哩哔哩1、超多福利:...