简体   繁体   English

如何在 React 的 Ionic 5 中锁定幻灯片

[英]How to lock slides in Ionic 5 in React

I don't have any idea how to lock slides in eg first IonSlide.我不知道如何在第一个 IonSlide 中锁定幻灯片。 I didn't find explanation in web.我在 web 中没有找到解释。

const Slider: React.FC = () => {
return(
<IonApp>
    <IonContent >

 <IonSlides>

        <IonSlide >
         ...
        </IonSlide>

        <IonSlide>

          ...
        </IonSlide>

 </IonSlides>
</IonContent>
</IonApp>
)
}

Take a look at the useRef Hook.看看useRef Hook。 You can get a reference to your ion-slides element and call the lockSwipes method after the Swiper initialization using the ionSlidesDidLoad event:您可以获得对ion-slides元素的引用,并在 Swiper 初始化后使用ionSlidesDidLoad事件调用lockSwipes方法:

import React, { useRef } from 'react';

const Slider: React.FC = () => {
  const slidesEl = useRef(document.createElement('ion-slides'))

  const handleSlidesLoad = () => {
    slidesEl.current.lockSwipes(true)
  }
  return (
    <IonApp>
      <IonContent>
        <IonSlides onIonSlidesDidLoad={() => handleSlidesLoad()} ref={slidesEl}>
          <IonSlide>
            ...
          </IonSlide>
          <IonSlide>
            ...
          </IonSlide>
        </IonSlides>
      </IonContent>
    </IonApp>
  )
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM