Jump to content
Search Community

Draggable update() is not updating when in throwing state

Fullsix SL test
Moderator Tag

Recommended Posts

Hi,

 

I'm trying to reorder elements in a carousel to make it infinite. When im dragging there is no problem, i can reorder them and it's all ok. But when i release it, throwing it, the update() method of the draggable don't update the value of the Inertia Plugin. Is there a way to do this?

 

Draggable instantiation:

const draggableConfig = {
    throwResistance: 10000,
    minimumMovement:6,
    onThrowUpdate: throttle((e) => {
        this.updateInnerElements();
    },50),
    onDrag: throttle((e) => {
        this.updateInnerElements();
    }, 50),
}

this.works when called onDrag, but no when called by onThrowUpdate

 

updateInnerElements () {
    let dirty = false;
    console.log("x", this.draggable.draggableInstance.x)
    if(this.draggable.draggableInstance.x < -this.itemWidth) {
        console.log("left", this.draggable.draggableInstance.x + this.itemWidth)
        this.slides.push(this.slides.shift());
        this.slides.forEach(x => this.wrapper.appendChild(x));
        gsap.set(this.wrapper, {x: this.draggable.draggableInstance.x + this.itemWidth});
        this.draggable.draggableInstance.update();
        dirty = true;

    }
    if(this.draggable.draggableInstance.x >= 0) {
        console.log("right")
        this.slides.unshift(this.slides.pop());
        this.slides.forEach(x => this.wrapper.appendChild(x));
        gsap.set(this.wrapper, {x: this.draggable.draggableInstance.x - this.itemWidth});
        this.draggable.draggableInstance.update();
        dirty = true;
    }
    if(dirty) {
        console.log('updated');
        console.log("afterX", this.draggable.draggableInstance.x)
    }
}

Can you help me? Thanks

 

Link to comment
Share on other sites

I am trying to make the scroll of slides infinite swaping slides from start to end and from end to start when they are not in the visible area. If you disable the intertia in the codepen, everything goes ok, you can drag and drag and you never reach the end...

Link to comment
Share on other sites

ok, i see, moving the items individually and using wrap and a proxy is mentally more complex for me (didn't know about that utilities, which are cool), but indeed is a more elegant solution that swapping the elements in the container.

 

btw is ok then that the inertia plugin doesn't care about draggable.update()?

 

Thanks for your support.

Link to comment
Share on other sites

Yes, in my example, when i do

 

var frame = 1;
function onUpdateHandler(){
  console.log("frame " + frame);
  frame++;
  console.log("before x:", draggableInstance.x)
  if(draggableInstance.x > 800) {
	gsap.set(el, {x: draggableInstance.x - 800});
	draggableInstance.update();
	console.log("after x:", draggableInstance.x)
  }
}
// While dragging:
// Frame 1: before x = 1000, after x = 200;
// Frame 2: before x = 200
// While throwing:
// Frame 1: before x = 1000, after x = 200;
// Frame 2: before x = 1000, after x = 200;

while dragging, i can draggable.update() and the value is retained in the next frame (intented behavior),but when i release the mouse and inertia plugin is working, the value "resets" itself to its previous state

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...