gpt4 book ai didi

javascript - 减少 translate-x 值

转载 作者:行者123 更新时间:2023-11-30 15:17:07 26 4
gpt4 key购买 nike

我正在构建一个旋转木马,每当用户点击下一个按钮时,转换值需要更新 -20%。

第一次点击时,旋转木马移动了 -20%,这很好,但是每次点击后,该值减少不到 20% - 值为 16% 并继续减少到 20 以下 - 不确定为什么?我需要该值每次点击仅减少 20%。

这是我更新的解决方案代码:

const handleCarouselNext = function* (payload) {
const currentIndex = payload.currentIndex;
const slides = document.getElementsByClassName('CYHH-carousel-carousel')[0];
slides.style.transform = 'translateX(-' + (100 - constants.slideAnimation) + '%)';
constants.slideAnimation = constants.slideAnimation - 20;
yield put({ type: actions.CAROUSEL_NEXT_DONE, payload: inc(currentIndex) });
};

最佳答案

16% = 20% *0.8

换句话说,您在每次点击后应用“0.8 倍”而不是仅一次(因为您希望将其保持在恒定的 20%。)

所以只需删除它就可以解决问题:constants.slideAnimation = constants.slideAnimation * 80/100;

关于javascript - 减少 translate-x 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44303513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com