有切换方块的按钮,有转场效果。而且我需要在单击后一段时间后才能单击此按钮。否则,会出现不必要的视觉错误。还有 2 个按钮,一个后退 ( prev),一个前进 ( next)
next.addEventListener('click', function() {
var activeBlock = document.querySelector('.content > .block.active');
var nextBlock = activeBlock.nextElementSibling;
if (nextBlock.classList.contains('block')) {
nextBlock.classList.add('active', 'fadeIn');
nextBlock.style.display = 'flex';
setTimeout(function () {
nextBlock.classList.remove('fadeIn');
nextBlock.style.opacity = '1';
}, 500);
}
else {
firstBlock.classList.add('active', 'fadeIn');
firstBlock.style.display = 'flex';
setTimeout(function () {
firstBlock.classList.remove('fadeIn');
firstBlock.style.opacity = '1';
}, 500);
}
activeBlock.classList.add('fadeOut');
setTimeout(function () {
activeBlock.classList.remove('fadeOut');
activeBlock.classList.remove('active');
activeBlock.style.opacity = '0';
activeBlock.style.display = 'none';
}, 500);
});
2 个回答