angular - 角度 8 中的自动图像滑块(自定义和简单:2019 年 12 月)
解决方案
是的,我花了 3 个小时后找到了解决方案。
1/ 组件.ts
gOnInit() {
this.Repeat();
}
Repeat() {
setTimeout(() => {
this.__FunctionSlide();
this.Repeat();
}, 2000);
}
__FunctionSlide() {
const slides = Array.from(document.getElementsByClassName('mall-show-slide'));
if (slides === []) {
this.Repeat();
}
for (const x of slides) {
const y = x as HTMLElement;
y.style.display = 'none';
}
if (this.startIndex > slides.length - 1) {
this.startIndex = 0;
const slide = slides[this.startIndex] as HTMLElement;
slide.style.display = 'block';
this.startIndex++;
} else {
const slide = slides[this.startIndex] as HTMLElement;
slide.style.display = 'block';
this.startIndex++;
}
}
2/样式.css
.mall-slide {
position: absolute;
top: 155px;
background-color: #f5f5f5;
width: 100%;
height: 430px;
z-index: -1;
}
.mall-slide .slid-content {
width: 100%;
height: 320px !important;
overflow: hidden;
}
.mall-slide .slid-content .mall-carousel-ind {
position: absolute;
top: 290px;
width: 100%;
line-height: 0!important;
text-align: center;
font-size: 0;
z-index: 10;
}
.mall-carousel-ind ul {
display: inline-block;
padding: 5px;
background-color: rgba(0, 0, 0, .2);
border-radius: 10px;
-webkit-transition-duration: .3s;
transition-duration: .3s;
}
.mall-carousel-ind li {
display: inline-block;
width: 10px;
height: 10px;
margin: 0 3px;
font-size: 14px;
background-color: #e2e2e2;
background-color: rgba(255, 255, 255, .5);
border-radius: 50%;
cursor: pointer;
-webkit-transition-duration: .3s;
transition-duration: .3s;
}
.mall-carousel-ind li.mall-this {
background-color: #fff;
filter: alpha(opacity=100);
-moz-opacity: 1;
opacity: 1;
width: 30px;
border-radius: 14px;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
3/ HTML
<div class="mall-slide">
<div class="slid-content">
<div class="mall-show-slide fade" *ngFor="let item of Imagedata;">
<img src="{{item}}" style="width:100%">
</div>
<div class="mall-carousel-ind">
<ul>
<li *ngFor="let item of Imagedata; let i = index;" [class.mall-this]="startIndex - 1 === i"></li>
</ul>
</div>
</div>
</div>
推荐阅读
- c# - 从空项目创建 ASP.NET Core 3 MVC
- java - 将 ByteBuffer 转换为字符串删除位于字符串末尾的字符串换行符?
- c# - 从 url 位置下载 PDF 文件会生成 HTML 文件
- ios - 弱到强引用仍然在查找时崩溃
- ios - 如何在 Flutter 中对齐 SingleScrollView 中的组件?
- python - Python:两台计算机之间的目标不可达(端口不可达)
- python - Yolov3中的自定义锚点
- c# - C# LINQ to Entities - 检索等待列表记录的所有记录和位置
- python - Peewee 如何选择每 n+ 行?
- java - Android CardView 使用 app:cardCornerRadius="5dp" 时不圆角