javascript - JS加后缀整数并从1旋转到4
问题描述
我必须将类的后缀更改为.background-1
等.background-2
。在 4 之后它又回到 1。就像一个旋转木马。
我的触发器是点击,它可以在下面看到:
$('.arrow-next').click(function () {
// Here should be the code
});
解决方案
这会做...
const $carousel = $('.carousel');
$('.arrow-next').click(function() {
if ($carousel.classList.contains('background-1')) {
$el.classList.remove('background-1');
$el.classList.add('background-2');
} else if ($carousel.classList.contains('background-2')) {
$el.classList.remove('background-2');
$el.classList.add('background-3');
} else if ($carousel.classList.contains('background-3')) {
$el.classList.remove('background-3');
$el.classList.add('background-4');
} else if ($carousel.classList.contains('background-4')) {
$el.classList.remove('background-4');
$el.classList.add('background-1');
}
});
推荐阅读
- jquery - 如何将滚动条保持在先前的位置?
- .net-core - 机器人配置不包含 ID 为“basic-bot-LUIS”的“luis”服务类型。(.NET 核心)
- javascript - 如何在 safari 应用程序和从 safari 应用程序扩展资源文件夹加载的 html 页面之间进行通信
- node.js - Alexa ASK SDK V2 Nodejs Dialog Delegate Directive 覆盖卡响应
- php - Laravel 相同的 cookie 值
- java - 部署 jar Tomcat 8
- html - 子集数据框时值不在索引中
- apache-spark - ELK apache spark应用日志
- reverse-engineering - 如何理解 IR 校验和
- api - AutoML API 设置问题