[英]adjust ionic slides time to change slide every one day
I tried to implement carousel in my ionic application and While going through Ionic documentation I found ionic-slides
does same things.我尝试在我的 ionic 应用程序中实现 carousel 并且在浏览 Ionic 文档时我发现
ionic-slides
做同样的事情。 How do I change the timing of slide ?如何更改幻灯片的时间? I tried using following code but it doesn't shows any changes to the slide.
我尝试使用以下代码,但它没有显示对幻灯片的任何更改。 It keeps sliding frequently although I changed the time.
尽管我更改了时间,但它仍然经常滑动。 I want to keep change slide after 24 hrs.
我想在 24 小时后保持更换幻灯片。
.ts .ts
option = {
slidesPerView: 1,
speed: 86400000,
centeredSlides: true,
loop: true,
spaceBetween: 5,
autoplay: true,
};
.html .html
<ion-slides [options]="option">
<ion-slide>
<ion-card>
<img src="../../../assets/image01.jpg" />
</ion-card>
</ion-slide>
<ion-slide>
<ion-card>
<img src="../../../assets/image02.jpg" />
</ion-card>
</ion-slide>
<ion-slide>
<ion-card>
<img src="../../../assets/image03.jpg" />
</ion-card>
</ion-slide>
</ion-slides>
.scss .scss
ion-card {
width: 100%;
height: 500px;
box-shadow: none;
img {
object-fit: cover;
width: 100%;
}
}
.swiper-slide-active {
ion-card {
img {
transform: scale(1, 1);
}
}
}
.swiper-slide {
transition: 1000ms all ease-in-out;
}
thank you.谢谢你。
You could leverage the Ionic slider methods to control the slide behavior with more control vs using the configuration object.与使用配置对象相比,您可以利用Ionic 滑块方法通过更多控制来控制滑块行为。 The below example demonstrates one proof of concept, but I do add some edge case and further considerations for improvement.
下面的示例演示了一个概念证明,但我确实添加了一些边缘情况和进一步的改进考虑。
First thing you would need to do is reference Ionic Slides in your component like so:您需要做的第一件事是在您的组件中引用 Ionic Slides,如下所示:
import { IonSlides } from '@ionic/angular';
export class HomePage implements OnInit {
@ViewChild(IonSlides, { static: true }) slides: IonSlides;
Second, you would then need to write some code that would call Ionic's nextSlide based on the 24 hour threshold.其次,您需要编写一些代码,根据 24 小时阈值调用 Ionic 的 nextSlide。 I would start off with a smaller threshold for testing purposes before expanding to 24 hours.
在扩展到 24 小时之前,我会从一个较小的测试阈值开始。 Here is some psuedo code to demonstrate the idea:
下面是一些伪代码来演示这个想法:
// need to call this every on a triggered interval (be cautious of memory leaks)
nextSlide = () => {
this.now = Date.now();
this.elapsed = this.now - this.last;
if (this.elapsed > this.threshold) {
this.slides.getActiveIndex().then((activeIndex)=> {
if(activeIndex < this.slideCount) {
this.slides.slideNext();
}
else {
this.slides.slideTo(0);
}
})
}
}
I would consider the following before continuing with the implementation:在继续实施之前,我会考虑以下几点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.