javascript - 如何使用淡入淡出效果为某些像素设置动画?
问题描述
我使用这个插件创建了一个具有渐变效果的滑块 https://github.com/crystal-lang/crystal-presents
我的逻辑是
- 我把我的幻灯片放在不同的左边
0, 25%, 50% ,75%
(如果有四张幻灯片)。 - 现在我将这些侧移到
0px
用户使用 next button 导航时。将转换 translateX(0) 与0 Sec
. 并在 5 秒内将不透明度从 0 增加到 1。
我的问题。
褪色很好。
但我想
right to left or left to right
根据用户选择的选项翻译几个像素。也就是说目前滑动移动
1000px (his position) to 0px (expecting position) in zero sec
。我希望它应该移动100px to 0px
(小距离),3 second
以便它看起来滑动也在滑动(小像素)。
可能吗 ??
这是我的代码 https://codesandbox.io/s/nostalgic-smoke-f5y51?file=/slider.js
prevSlide() {
const t = this;
const opts = t.options;
let nextSlide = t.activeSlide - 1;
if (t.activeSlide <= 1 && !t.isEnabledOption("loop")) {
return;
}
if (nextSlide < 1) {
nextSlide = t.slidesLength;
}
if (isFunction(opts.beforeChange)) {
opts.beforeChange.call(t, t, t.activeSlide, nextSlide, t.slidesLength);
}
t.activeSlide <= 1 && t.isEnabledOption("loop")
? (t.activeSlide = t.slidesLength)
: (t.activeSlide -= 1);
t._setActiveSlide();
}
nextSlide() {
const t = this;
const opts = t.options;
let nextSlide = t.activeSlide + 1;
if (t.activeSlide >= t.slidesLength && !t.isEnabledOption("loop")) {
t._paused = true;
return;
}
if (nextSlide > t.slidesLength) {
nextSlide = 1;
}
if (isFunction(opts.beforeChange)) {
opts.beforeChange.call(t, t, t.activeSlide, nextSlide, t.slidesLength);
}
t.activeSlide >= t.slidesLength && t.isEnabledOption("loop")
? (t.activeSlide = 1)
: (t.activeSlide += 1);
t._setActiveSlide();
}
解决方案
推荐阅读
- java - 异常处理和测试(JUnit5):SpringBoot RestTemplate
- html - 将图标栏与 HTML 中的下拉菜单结合起来?
- python-3.x - Python - MySql:mycursor.execute,选择查询在while循环中使用时返回相同的值
- reactjs - 将 prop 值之一更改为空对象时反应功能组件不会重新渲染/返回其 JSX
- css - 通过模块 scss 文件传递 SASS 变量
- flutter - 无法在颤振中连接 HubConnection 与 signleR
- node.js - 在 windows 中使用单个命令启动多个节点微服务
- r - 如何在 R 中绘制两个带有单个 x 轴的分组条形图(垂直)?
- python - 使用 I/O Bound 应用程序导入静态还是动态更好
- windows - 来自守护程序的错误响应:无法使用重启策略创建“AutoRemove”容器