简体   繁体   English

调整离子幻灯片时间以每天更换幻灯片

[英]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:在继续实施之前,我会考虑以下几点:

  • Should the threshold be mapped to a user vs browser session instance?阈值是否应该映射到用户与浏览器会话实例? This would open door to being more precise, because you can persist the user's last visit and compare - see pseudo code这将为更精确打开大门,因为您可以保留用户的上次访问并进行比较 - 请参阅伪代码
  • Be careful of memory leaks when building out the threshold logic.在构建阈值逻辑时要小心内存泄漏。 If using intervals or setTimeouts, be sure to clear them in the correct Ionic lifecycle methods .如果使用间隔或 setTimeouts,请确保在正确的Ionic 生命周期方法中清除它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不将每张幻灯片设置为一个背景的情况下更改每张幻灯片的数据属性? - How do I change each slide's data- attribute without setting every slide to one background? 调整javascript滑块,以使第一张幻灯片的超时时间与其余幻灯片不同 - Adjust javascript slider so that first slide has a different timeout to the rest of the slides 我右边的图片改变了幻灯片,但左边的图片卡在了第一张幻灯片上 - my right image changes slides but the left one is stuck on the first slide 如何使用 cursor hover 更改幻灯片而不是单击? 当 cursor 在幻灯片上时,我正在尝试更改幻灯片 - How can I use cursor hover to change slides instead of clicking? I am trying to change slides when cursor is up on the slide RAILS / HTML:每7秒钟更改一次图片幻灯片 - RAILS/HTML: Change image slide every 7 seconds 在一天中的特定时间更改选项卡 - change tab at specific time of the day 根据一天中的时间更改图像 - Change an image based on the time of day Js:每次在部分内滚动并返回到幻灯片部分时,在所有幻灯片中都会出现一个div - Js: Make a div appear in all slides each time scrolling within sections and returning to slide section 在Ionic 4中每隔10秒如何下一步移动Ion-Slides? - How to move Ion-Slides next after every 10 second in Ionic 4? 在彼此相邻的多个幻灯片中拆分引导程序的轮播幻灯片并更改箭头的可见性 - Split bootstrap's carousel slide in multiple slides next to each other and change visibility of arrows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM