Jump to content
Search Community

OSUblake last won the day on September 16 2023

OSUblake had the most liked content!

OSUblake

Moderators
  • Posts

    9,196
  • Joined

  • Last visited

  • Days Won

    708

Posts posted by OSUblake

  1. Also, you can reduce all this code

     

    const sticker = document.createElementNS(
      "http://www.w3.org/2000/svg",
      "image"
    );
    sticker.setAttributeNS(null, "height", "64");
    sticker.setAttributeNS(null, "width", "64");
    sticker.setAttributeNS("http://www.w3.org/1999/xlink", "href", path);
    sticker.setAttributeNS(null, "x", 64 * i + 16 + 8 * i);
    sticker.setAttributeNS(null, "y", "0");
    sticker.setAttributeNS(null, "visibility", "visible");
    sticker.classList.add("sticker");
    sticker.dataset.type = `sticker-${i}`;
    parent.appendChild(sticker);

     

    using insertAdjacentHTML.

    https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML

     

    parent.insertAdjacentHTML("beforeend", `
      <image class="sticker" x="${64 * i + 16 + 8 * i}" y="0" height="64" width="64" href="${path}" data-type="sticker-${i}"></image>
    `);
    
    
    // if you need the element 
    const element = parent.lastElementChild;

     

     

    • Like 4
  2. When you do bind inline like that, you don't have a reference to the new function, so you can't remove it. That's just how it works, and isn't related to gsap.

     

    So you either need store the bound function.

    init():void{ 
      this.boundCheck2 = this.check2.bind(this, body)
      gsap.ticker.add(this.boundCheck2);
     }
    
        protected check2($body): void
        {
            if ($body.x === 0 && $body.y === 0)
            {
                gsap.ticker.remove(this.boundCheck2);
            }
        }

     

    Or use a class field arrow function.

     

    check2 = () => {
    
      if (body.x === 0 && body.y === 0)
      {
         gsap.ticker.remove(this.check2);
      }
    }
    
    init():void{ 
      gsap.ticker.add(this.check2);
    }

     

     

    • Like 3
    • Thanks 1
  3. "touchstart click" isn't a valid name. That's like jQuery syntax. Only 1 name per event listener.

    clickableDots[i].addEventListener("touchstart", slideAnim);
    clickableDots[i].addEventListener("click", slideAnim);

     

    But I think you just need "click". It should work for touch too.

     

    • Like 2
  4. What does your code look like?

     

    If you do it just like this, you shouldn't have any problems.

     

    var onTick = myCallback.bind(myScope, "param1", "param2");
    
    gsap.ticker.add(onTick);
    
    ...
    gsap.ticker.remove(onTick);

     

  5. For hooks, you should create your animations with useRef, like here.

     

    For your onReverseComplete, I'm not sure how to do that because it looks like you are capturing flagA and flagB values in a closure, which wouldn't update. My suggestion would be to use a class to work around that. 

     

    onReverseComplete = () => {
      if (this.state.flagA) {
        // do A stuff here
      }
      if (this.state.flagB) {
        // do B stuff here
      }
    }

     

     

    • Like 5
  6. On 4/9/2020 at 10:26 AM, Greg Stager said:

    and am a veteran of the US Army and Iraq war.

     

    Cool! Former Army here. I was a 13M, multiple launch rocket systems (MLRS), but the only deployment I ever did was stateside to the Marine Corps base in 29 Palms, California.

     

  7. Just now, Shrug ¯\_(ツ)_/¯ said:

    GSAP code battles in every thread around here. 😄

     

    Ha, yeah! A good thread would have like 3 or 4 people coming up with unique and better solutions.

     

    • Like 1
  8. 8 minutes ago, Shrug ¯\_(ツ)_/¯ said:

    There is so much amazing stuff on this forum when you dig around for it (its worth digging). Sometimes I head back into pages 300 to 400+ and just read old posts, you can discover all kinds of awesome stuff laying around.  👍

     

    It seems like the number of good/interesting questions has dried up lately, so most of my good posts are several years old. Nowadays most questions are about scrolling, which don't interest me.

     

    • Like 1
  9. 14 minutes ago, Greg Stager said:

    I was thinking maybe I could store the current x,y when I start dragging and tween to that same x,y if the hitTest is true.

    Perhaps I will play with that concept.

     

    That might be a good enough solution. The only problem with that is that you might not be able to get objects butting up against each other. For example, if you're dragging something that is 10px away from hitting another object, and then on the next drag it's hitting that object, you will end up moving it back 10px back, leaving a little gap between them.

     

    If you can live with that, then go for it. And if you are using circles, then using circle collision detection will work better than Draggable's hit test.

     

    See the Pen YXpdYN by osublake (@osublake) on CodePen

     

     

  10. It's a scope issue from your requestAnimationFrame calls.

     

    Take your pick. I like using class fields for events.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_fields

     

    
    // function as class field
    class MyClass {
       
      update = () => {
        console.log(this.foo);
      }
      
      constructor() {
        this.foo = "FOO"
        
        requestAnimationFrame(this.update)
      }
    }
    
    // function inside constructor
    class MyClass {
      
      constructor() {
        this.foo = "FOO"
        
        this.update = () => {
          console.log(this.foo);
        }
        
        requestAnimationFrame(this.update);
      }
    }
    
    // use a function to call it
    class MyClass {
      
      constructor() {
        this.foo = "FOO"
        
        requestAnimationFrame(() => this.update())
      }
      
      update() {
        console.log(this.foo);
      }
    }

     

     

     

     

    • Like 4
    • Thanks 1
×
×
  • Create New...