Here's a working sample with style.display = 'none'
instead of zIndex
(I don't think zIndex
is well suited for this use case.) :
import 'dart:html';
void main(){
query(".rightArrow img").onClick.listen((e) => cssRightArrow());
query(".leftArrow img").onClick.listen((e) => cssLeftArrow());
}
cssRightArrow(){
final elements = query(".carousel").children;
// looking for the one currently displayed
final Element current = elements.firstWhere((e) => e.style.display != 'none');
final currentIndex = elements.indexOf(current);
// hide current and show next one
if (currentIndex + 1 < elements.length) {
current.style.display = 'none';
elements[currentIndex + 1].style.display = '';
}
}