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. 5 hours ago, GreenSock said:

    I would assume that gets the UMD version of ScrollTrigger, but the ES Module of GSAP (the core). Shouldn't it look like this?

    
    import { gsap } from 'gsap/dist/gsap';
    import { ScrollTrigger } from "gsap/dist/ScrollTrigger";

     

     

    I think import { gsap } from 'gsap' gets the umd version in nextjs based on the main field in the package.json.

     

     

    • Like 4
  2. 1 hour ago, yulia said:

    Gsap only starts working if I connect it on the page where the component is imported.

     

    That's the correct way. Gsap isn't global, so you have to import it in every file where you use it.

     

     

    • Like 2
  3. Hard to say what if any performance problems there might be without seeing a demo.

     

    The quickSetter just set values, so maybe you are mistaking that for performance problems. 🤷‍♂️ If you need a smooth transition, then you can interpolate changes like in this demo.

     

     

    See the Pen WNNNBpo by GreenSock (@GreenSock) on CodePen

     

    And the most performant way to use quickSetter is to specify the property.

    this.hillsXSetter = gsap.quickSetter(this.hills, 'x', 'px')
    
    this.hillsXSetter(s / 5)

     

    Also, setting will-change: transform in your css for the images can improve performance.

     

    • Like 4
  4. On 6/26/2020 at 6:46 PM, Ivan Dzhurov said:

      return new Promise((done): void => {

          gsap.to(this.speed, {

              duration: this.spinConfig.startTime,

              ease: Back.easeOut,

              value: this.config.speed,

              delay: this.config.startDelay,

              onUpdate: () => console.log(this.speed.value),

              onComplete: (): void => done()

          });

      });

     

    Just a little tip. You don't need to wrap the animation in a promise as gsap animations are promisified, i.e. returning the animation is the same as returning a promise that will resolve on complete.

     

    return gsap.to(this.speed, {
      duration: this.spinConfig.startTime,
      ease: Back.easeOut,
      value: this.config.speed,
      delay: this.config.startDelay,
      onUpdate: () => console.log(this.speed.value)
    });

     

    https://greensock.com/docs/v3/GSAP/Tween/then()

    https://greensock.com/docs/v3/GSAP/Timeline/then()

     

     

    • Like 2
  5. 2 hours ago, mallanaga said:

    If I position the element manually, though, it goes back to jumping

     

    How are you positioning it?

     

    gsap.getProperty() returns the transform: translate values, which would be different if you were setting the position with left/top. 

     

    The transform can be set in your CSS, inline, or with gsap. If you want to use to left/top, then this would need to change.

     

    const dx = cardX + (parentX - gsap.getProperty(newParent, "x"));
    const dy = cardY + (parentY - gsap.getProperty(newParent, "y"));

     

    To something like this.

    const a = newParent.getBoundingClientRect();
    const b = oldParent.getBoundingClientRect();
    
    const dx = cardX + (b.left - a.left);
    const dy = cardY + (b.top - a.top);

     

     

    • Like 1
  6. 4 hours ago, mallanaga said:

    As soon as I move it, it jumps again.

     

    When you move the area and then drag the card to the table, sending just the position of the card would be incorrect. The position on the table would be the area x/y + the card x/y. 

     

    If needed, you can grab the x and y values of any element using gsap.getProperty().

    https://greensock.com/docs/v3/GSAP/gsap.getProperty()

     

    If you're moving the card from the table to another part of the table, then sending just card's x/y would be ok. There would be no need to do any sort of calculation. Just tween to the new position.

     

    • Like 1
  7. 4 hours ago, mallanaga said:

    I feel like I'm honing in on the culprit. I move the "Draw" area to the middle of the table on page load.

     

    Does that need to be draggable? If every client can move that around, then I think you're going to have to add in some more logic as it's going offset stuff. If it's stationary, then it will be much easier.

     

     

  8. If you need to animate x and y, you really don't need to use pixi plugin. x and y are properties of the display object. The plugin helps out for stuff like scale.

     

    tl.to(part,{
      pixi:{
        scale:0.5
      },      
      duration: 4,
      x: 500,
      y: 500,
      modifiers:{
        x:function(x){return 0; } // for test :D 
      }
    });

     

    • Like 4
  9. 59 minutes ago, mallanaga said:

    Regarding the update. The clients won't have the benefit of an onPress event. Won't they need a "manual" call to update? or would the tween be sufficient?

     

    No. A client only needs to call update when they start dragging. It doesn't need to happen on every client.

     

    I had a real-time dragging demo up on CodePen, but it looks like my Firebase account is all screwed up.

     

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

     

    But you can see how I handle the dragging and animation in the MagnetController class. Every draggable was an instance of the MagnetController class. The onChange event would fire when something changed, like dragging the magnet.

     

    class MagnetController {
        
        active  = false;
        time    = 0;
        board   = document.querySelector(".board");
        data    = this.firebaseData.magnet(this.magnetId);      
        unwatch = this.data.$watch(this.onChange.bind(this));
    
        draggable = null;
    
        constructor(
          private $element, 
          private $scope, 
          private $timeout, 
          private firebaseData) {
                           
          this.data.$loaded(event => {
            
            if (!this.data.content || !this.data.zIndex) {
              TweenLite.set($element, { autoAlpha: 0 });
              this.remove();
              return;
            }
            
            this.init();
          });
          
          this.data.$ref().onDisconnect().update({ locked: false });
        }
    
        init() {
          
          this.draggable = new Draggable(this.$element, {
            onDrag: this.onDrag,
            onPress: this.onPress,
            onRelease: this.onRelease,
            zIndexBoost: false,
            callbackScope: this,
            liveSnap: {
              x: n => this.active ? n : this.data.x,
              y: n => this.active ? n : this.data.y
            }      
          });
        }
    
        onChange(event) {
               
          var config = {
            rotation : this.data.rotation,
            zIndex   : this.data.zIndex || Draggable.zIndex
          };
    
          if (!this.active) {
            config.x = this.data.x;
            config.y = this.data.y;
          }
          
          TweenLite.to(this.$element, this.time, config);
          
          this.time = 0.07;
        }
    
        onPress(event) {
          
          if (this.data.locked) return;
          
          this.draggable.update();      
          this.updateDraggable();
          this.active = true;
          this.data.locked = true;
          this.data.zIndex = Draggable.zIndex++;
          this.data.$save(); 
        }
    
        onRelease(event) {
                
          if (!this.draggable.hitTest(this.board)) {
            this.remove();
            return;
          }
          
          if (!this.active) return;
                
          this.active = false;
          this.data.locked = false;
          this.data.$save(); 
        }
    
        onDrag(event) {
          
          if (!this.active) return;
          
          this.data.x = this.draggable.x;
          this.data.y = this.draggable.y;
          this.data.$save();
        }
    
        remove() {
          
          this.draggable && this.draggable.kill();
          this.unwatch();
          this.data.$remove().then(ref => {        
            this.$scope.$destroy();
            this.updateBoard();
          }, error => {
            console.log(error);
          });
        }
      }

     

     

    • Like 2
×
×
  • Create New...