Added carousel.js for showing/hiding elements

This commit is contained in:
Niko 2022-02-14 13:33:29 +01:00
parent 00d4a81aef
commit 6f682bc54b
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
app.carousel = {
hasNext: function(mod, i) {
i = i || mod._current;
return i < mod._size() - 1;
},
hasPrev: function(mod, i) {
i = i || mod._current;
return i > 0;
},
next: function(mod) {
if (!app.carousel.hasNext(mod))
return false;
return app.carousel.set(mod, mod._current+1);
},
prev: function(mod) {
if (!app.carousel.hasPrev(mod))
return false;
return app.carousel.set(mod, mod._current-1);
},
set: function(mod, i) {
const elements = mod._elements();
const current = elements[mod._current];
const next = elements[i];
if (mod._animation !== undefined) {
// TODO: animation run here
}
for (var j = 0; j < elements.length; j++)
elements[j].style = 'display: none';
next.removeAttribute('style');
mod._current = i;
return true;
},
};