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

相关内容

热门资讯

透视模板!竞技联盟辅助插件(W... 透视模板!竞技联盟辅助插件(WePoKer免费)确实有辅助软件(哔哩哔哩);1、完成竞技联盟辅助插件...
透视妙计!菠萝辅助器免费版的功... 透视妙计!菠萝辅助器免费版的功能介绍(WePoKer官方)果然有辅助插件(哔哩哔哩)1、完成菠萝辅助...
透视指南书!wepoker可以... 透视指南书!wepoker可以开透视吗(WePoKer好牌)原来存在有辅助神器(哔哩哔哩)1、该软件...
透视办法!拱趴大菠萝万能辅助器... 透视办法!拱趴大菠萝万能辅助器(WePoKer大神)其实存在有辅助软件(哔哩哔哩)亲,关键说明,拱趴...
透视项目!hhpoker是内部... 透视项目!hhpoker是内部控制吗(WePoKer祈福)都是存在有辅助方法(哔哩哔哩)1、金币登录...
透视教材!智星菠萝可以辅助吗(... 透视教材!智星菠萝可以辅助吗(HHpoker工具)好像是真的有辅助方法(哔哩哔哩)1、这是跨平台的智...
透视课程!德州局HHpoker... 透视课程!德州局HHpoker透视脚本(WPK辅助器)一贯有辅助工具(哔哩哔哩)1、用户打开应用后不...
透视项目!wepoker透视破... 透视项目!wepoker透视破解版(HHpoker内部)切实存在有辅助教程(哔哩哔哩)wepoker...
透视妙计!菠萝辅助器免费版的特... 透视妙计!菠萝辅助器免费版的特点(WePoKer数据)一直存在有辅助软件(哔哩哔哩)1、菠萝辅助器免...
透视方案!菠萝德州透视脚本(W... 透视方案!菠萝德州透视脚本(WePoKer大神)好像是有辅助app(哔哩哔哩)1、菠萝德州透视脚本透...