根据网站上的教程,我创建了一个轮播。这是我的轮播的html代码;
<div class="row carousel" (mouseover)="mouseCheck()">
<!-- For the prev control button -->
<button class="control" style="left: 30px;" (click)="prevButton()">
<span class="arrow" style="transform: rotate(45deg);"></span>
</button>
<div class="row car-allign">
<div *ngFor="let i of currentSlide;" style="width: 184px;" class="card CardBtw">
<div @carouselAnimation>
<!-- SOME CODE IN HERE -->
</div>
</div>
</div>
<!-- For the control buttons -->
<button class="control" style="right: 30px;" (click)="nextButton()">
<span class="arrow" style="transform: rotate(225deg);"></span>
</button>
</div>
我已经成功实现了动画。我想要的是让该转盘每10秒循环一次,而鼠标不在转盘上。如果用户将鼠标放在转盘上,则让这10秒钟从头开始。我实现了一个名为“ mouseCheck()”的功能,以检测鼠标是否在此上。但是我无法每10秒循环一次。我怎样才能做到这一点?
编辑:
这是大家都想要的代码。我的mouseover功能只是在鼠标打开时控制台记录日志(我创建了它,但是无法填充它,因为我无法跟踪时间:/)
我借助下一个和上一个按钮选择并隐藏显示的矢量。这是.ts中的函数(只是下一个按钮func,无论如何cus prev都与此类似);
//Start from the first vector
currentSlide = this.laptopSlide[0];
nextButton() {
//If the currentSlide is 0
if(this.currentSlide == this.laptopSlide[0])
this.currentSlide = this.laptopSlide[1]
//If currentSlide is 1
else if(this.currentSlide == this.laptopSlide[1])
this.currentSlide = this.laptopSlide[2]
//If current slide is 2
else if(this.currentSlide == this.laptopSlide[2])
this.currentSlide = this.laptopSlide[0];
}
您可以在mouseCheck()fn上创建setTimeout函数。
mouseCheck() {
if (condiction1 or click == true){
on.click() => {
"Give me a function conditione"
}
}else {
setTimeOut({
console.log("Change by inner content from typescript code on my component")
}, 2000)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句