Anyone know how to do this within Bubble, or of a similar plugin? Searched the docs but couldnt find anything
Trying to recreate the text animation on this: where when clicking a button, you should a subset of all elements of a list in an animated fashion, one at a time (and finally settle on displaying 1)
I suppose this can be done through JS Toolbox and writing some code, but wanted to check to see here if anyone knew first. Thanks!
That is cool. I have not seen something like that before, so donβt think there is a plugin for it, but likely does require some custom code.
You could maybe use an html element and run javascript workflow using the toolbox plugin to see if you could get either of these code pen examples to work.
@mm71593
I just got one to work
One your page place an html element and put the following code into it
<div id="app">
<div class="doors">
<div class="door">
<div class="boxes">
<!-- <div class="box">?</div> -->
</div>
</div>
<div class="door">
<div class="boxes">
<!-- <div class="box">?</div> -->
</div>
</div>
<div class="door">
<div class="boxes">
<!-- <div class="box">?</div> -->
</div>
</div>
</div>
<div class="buttons">
<button id="spinner">Play</button>
<button id="reseter">Reset</button>
</div>
</div>
<style>
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
#app {
width: 100%;
height: 100%;
background: #1a2b45;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.doors {
display: flex;
}
.door {
background: #fafafa;
width: 100px;
height: 110px;
overflow: hidden;
border-radius: 5px;
margin: 5px;
}
.boxes {
/* transform: translateY(0); */
transition: transform 1s ease-in-out;
}
.box {
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
}
.buttons {
margin: 1rem 0 2rem 0;
}
button {
cursor: pointer;
font-size: 1.2rem;
margin: 0 0.2rem;
border: none;
border-radius: 5px;
padding: 10px 15px;
}
.info {
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
}
</style>
Then setup a workflow for on page load (make sure you installed the toolbox plugin before).
The workflow will be the run javascript workflow
In the run javascript use the following code
(function () {
const items = [
'π',
'β',
'βοΈ',
'π¦',
'π',
'π©',
'π»',
'π»',
'π΅',
'π€‘',
'π¦',
'π',
'π',
];
const doors = document.querySelectorAll('.door');
document.querySelector('#spinner').addEventListener('click', spin);
document.querySelector('#reseter').addEventListener('click', init);
function init(firstInit = true, groups = 1, duration = 1) {
for (const door of doors) {
if (firstInit) {
door.dataset.spinned = '0';
} else if (door.dataset.spinned === '1') {
return;
}
const boxes = door.querySelector('.boxes');
const boxesClone = boxes.cloneNode(false);
const pool = ['β'];
if (!firstInit) {
const arr = [];
for (let n = 0; n < (groups > 0 ? groups : 1); n++) {
arr.push(...items);
}
pool.push(...shuffle(arr));
boxesClone.addEventListener(
'transitionstart',
function () {
door.dataset.spinned = '1';
this.querySelectorAll('.box').forEach((box) => {
box.style.filter = 'blur(1px)';
});
},
{ once: true }
);
boxesClone.addEventListener(
'transitionend',
function () {
this.querySelectorAll('.box').forEach((box, index) => {
box.style.filter = 'blur(0)';
if (index > 0) this.removeChild(box);
});
},
{ once: true }
);
}
for (let i = pool.length - 1; i >= 0; i--) {
const box = document.createElement('div');
box.classList.add('box');
box.style.width = door.clientWidth + 'px';
box.style.height = door.clientHeight + 'px';
box.textContent = pool[i];
boxesClone.appendChild(box);
}
boxesClone.style.transitionDuration = `${duration > 0 ? duration : 1}s`;
boxesClone.style.transform = `translateY(-${door.clientHeight * (pool.length - 1)}px)`;
door.replaceChild(boxesClone, boxes);
}
}
async function spin() {
init(false, 1, 2);
for (const door of doors) {
const boxes = door.querySelector('.boxes');
const duration = parseInt(boxes.style.transitionDuration);
boxes.style.transform = 'translateY(0)';
await new Promise((resolve) => setTimeout(resolve, duration * 100));
}
}
function shuffle([...arr]) {
let m = arr.length;
while (m) {
const i = Math.floor(Math.random() * m--);
[arr[m], arr[i]] = [arr[i], arr[m]];
}
return arr;
}
init();
})();
Thank you! That worked perfectly: thanks for adding that solution
1 Like
system
Closed
September 26, 2022, 5:56pm
5
This topic was automatically closed after 70 days. New replies are no longer allowed.