javascript - 如何在按钮中放大()(React swiper)?
问题描述
如何在swiper 的反应版本中使用缩放方法?我只想放大一个按钮并缩小另一个按钮。
在简历中,我想知道如何从其他兄弟组件放大和缩小 Swiper:
const MySwiper = () => {
return (
<div>
<button
onClick={() => {
// zoom out here ???
}}
>
ZOOM OUT
</button>
<button
onClick={() => {
// zoom in here ???
}}
>
ZOOM IN
</button>
<Swiper
id="main"
className="gallery-main"
tag="section"
zoom
wrapperTag="ul"
>
{slides}
</Swiper>
</div>
);
}
解决方案
经过很长时间为此寻找解决方案后,我得到了以下信息。您可以按如下方式制作zoom.in()
和zoom.out()
使用ref
for Swiper 组件:
const MySwiper = () => {
const ref = useRef(null)
return (
<div>
<button
onClick={() => {
// zoom out here
ref.current.swiper.zoom.out()
}}
>
ZOOM OUT
</button>
<button
onClick={() => {
// zoom in here
ref.current.swiper.zoom.in()
}}
>
ZOOM IN
</button>
<Swiper
ref={ref}
id="main"
className="gallery-main"
tag="section"
zoom
wrapperTag="ul"
>
{slides}
</Swiper>
</div>
);
}
但是您不能zoom.in
像 150% 这样的特定缩放比例,或者像 2 这样的特定比例。您只能放大到 Swiper 的缩放道具上建立的最大比例(默认为 3)或缩小到最小比例(默认为 1 )
推荐阅读
- haml - 中间人`concat`视图助手不起作用
- android - 使用api speedtest.net/speedtest-config.php android时被拒绝
- azure-storage - 检查 Azure 的共享访问签名有效性/过期
- android - Xposed 无法挂钩 getInstalledApplications
- python - 如何在 python 中将 DataFrames 添加为列?
- swift - Firebase 自定义触发器电子邮件模板
- python - 不使用 for 循环获取熊猫数据框中的先前元素
- vba - 根据电子邮件正文中的文本添加电子邮件收件人
- amazon-web-services - CORS 配置不允许访问私有 S3 存储桶(403 Forbidden)
- c - 检测宏参数是结构/直接类型还是 C 中的指针 - GCC 的内置函数是什么?