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

相关内容

热门资讯

技法透视!约局吧德州透视,we... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
发现透视"wepok... 发现透视"wepoker能不能透视辅助"开挂(透视)辅助神器(一分钟了解我来教教你)发现透视"wep...
练习透视!wepoker国外版... 您好:这款wepoker国外版透视游戏是可以开挂的,确实是有挂的,很多玩家在这款wepoker国外版...
策略透视!wepoker有透视... 策略透视!wepoker有透视功能吗,pokemmo脚本辅助,黑科技教程(有挂透视)-哔哩哔哩;无需...
课程透视!德州局怎么透视,po... 课程透视!德州局怎么透视,pokemmo免费脚本,总结教程(有挂教程)-哔哩哔哩1、下载安装好德州局...
操作透视!hhpoker免费透... hhpoker免费透视脚本是一款专注玩家量身打造的游戏记牌类型软件,在hhpoker免费透视脚本这款...
资料透视!werplan免费挂... 您好:werplan免费挂下载这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
绝活透视!德普之星怎么设置埋牌... 绝活透视!德普之星怎么设置埋牌,wepoker透视版下载,安装教程(有挂秘籍)-哔哩哔哩 【无需打开...
方式透视!wpk辅助,wepo... 方式透视!wpk辅助,wepoker怎么挂底牌,靠谱教程(有挂神器)-哔哩哔哩;亲,wepoker怎...
窍门透视!wepoker私人局... 窍门透视!wepoker私人局辅助器怎么用,红龙poker辅助指令,玩家教你(有挂秘笈)-哔哩哔哩 ...