Jump to content
Search Community

NightlyFly

Members
  • Posts

    5
  • Joined

  • Last visited

NightlyFly's Achievements

  1. Amazing thanks for the tips. I think this solved all my issues. Thanks for your time.
  2. Hi thanks for this! this is amazing, now the question is can the totalloops be stopped earlier to prevent going full rotation to find the winning number? because as shown in your post it stops directly, but it doesn't do that if the number is before or after the full totalloops ended. Basically if after the full rotations the number it stops on is 0 but it has to go to 10 it will speed up randomly. Thanks in advance! Sorry for all these questions, I cant find to see answers on the web regarding these issues. edit: You can see what I mean when you put winner class on 10.
  3. Hi So I made a mimial codepen to simplfy the issue. https://codepen.io/nightfly-student/pen/OJQvGzN I want the rotation stop at the win class after like 6 or 8x rotating and slowly slowing down on the .win class one
  4. Hi, that has been uses already! But it has nothing to do with my question sadly. I need to stop on the winning pos. Thanks anyways.
  5. Hi, I am working on a box system that users can open and have an animation to show what they have won. At the moment it is not working. const wrapper = document.querySelector(".c-container"); const boxes = gsap.utils.toArray(".c-item"); const wins = gsap.utils.toArray(".win"); let itemWidth = boxes[0].clientWidth; let wrapWidth = boxes.length * itemWidth; function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function getPosWinner(winner) { const boxes = gsap.utils.toArray(".c-item"); const index = boxes.findIndex((box) => (box = winner)); console.log(index); let itemWidth = boxes[0].clientWidth; let wrapWidth = boxes.length * itemWidth; let desiredStart; if (index === 0) { desiredStart = 0; } else { desiredStart = index * itemWidth; } let minDistanceToEdgeAllowed = 4; var desired = winner; var minPos = desiredStart + minDistanceToEdgeAllowed; var maxPos = desiredStart + itemWidth - minDistanceToEdgeAllowed; return getRandomInt(minPos, maxPos); } var spin; spin = gsap.timeline({ smoothChildTiming: true, autoRemoveChildren: true, //onComplete: openModal }); spin.set(boxes, { x: (i) => i * itemWidth, }); var pos = getPosWinner(wins[0]); spin.to(boxes, { duration: 7, delay: 0.2, ease: "circ.inOut", x: "-=10000", modifiers: { x: (x, target) => { const s = gsap.utils.wrap( -itemWidth, wrapWidth - itemWidth, parseInt(x) ); return `${s}px`; }, }, }) .to(boxes, { duration: 3, ease: "none", x: pos * -1, }); console.log(wins[0]); function openModal() { var myModal = document.getElementById("WinItem"); const modal = new Modal(myModal); modal.show(); } The JS code <div class="slider-container shadow rounded"> <BIconCaretDownFill class="fs-2 trigger" /> <BIconCaretUpFill class="fs-2 triggerTwo" /> <div class="c-container pt-1"> <div class="boxes"> <div v-for="item in lootItems" :key="item"> <div class="c-item" :class="{ win: item._id === winningItem }"> <LootboxContent class="lootboxItem text-light" :loot="item" /> </div> </div> </div> </div> </div> The container with items I start with making a array of items that people can win these items are inside the container. then I get the pos of the winning item. when I got that I spin the boxes a couple of times and then it should stop at the winning object (in the middle of the container) how it looks right now How it looks after its finished Hope you can help me. Thanks in advance edit: simplified codepen: https://codepen.io/nightfly-student/pen/OJQvGzN
×
×
  • Create New...