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模块。

相关内容

热门资讯

透视软件!hhpoker到底可... 透视软件!hhpoker到底可以作必弊吗(透视)雀友会手机透视辅助器app(都是有辅助工具)-哔哩哔...
透视系统!wpk模拟器(透视)... 透视系统!wpk模拟器(透视)微信小程序多乐辅助器下载(一贯有辅助插件)-哔哩哔哩1、下载好微信小程...
连日来!pokemmo辅助器(... 连日来!pokemmo辅助器(透视)游戏破解器100%破解(切实真的有辅助神器)-哔哩哔哩游戏破解器...
不少玩家反映!wepoker私... 不少玩家反映!wepoker私局辅助(透视)欢乐达人破解器(好像真的有辅助插件)-哔哩哔哩;1、起透...
最新消息!pokerworld... 最新消息!pokerworld修改器(透视)皮皮辅助软件是真的吗(其实有辅助神器)-哔哩哔哩1、金币...
据相关数据显示!拱趴游戏破解器... 据相关数据显示!拱趴游戏破解器(透视)小程序牵手跑得辅助器下载(总是存在有辅助平台)-哔哩哔哩进入游...
针对!wpk软件是正规的吗(透... 针对!wpk软件是正规的吗(透视)宝宝浙江辅助器(总是存在有辅助安装)-哔哩哔哩1、起透看视 宝宝浙...
透视美元局!wepokerpl... 透视美元局!wepokerplus透视脚本免费(透视)邳州友友有没有辅助软件(竟然存在有辅助工具)-...
有玩家发现!wejoker辅助... 有玩家发现!wejoker辅助脚本(透视)指尖四川刷无限钻石(其实真的有辅助安装)-哔哩哔哩1、指尖...
透视数据!红龙poker辅助(... 透视数据!红龙poker辅助(透视)老友广东辅助工具下载(原来真的有辅助修改器)-哔哩哔哩所有人都在...