Jump to content
Search Community

Draggable modifiers and snap (solved)

benoit test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I can't fork this pen from @OSUblake  but I found how to snap the draggable, so here is my trick :

 

var $overflow = $("#overflow");
var colors = ["#f38630","#6fb936", "#ccc", "#6fb936"];


var progress = 0;
var size = 500;

//initially colorize each box and position in a row
TweenMax.set(".box", {
  backgroundColor:function(i) {
    return colors[i % colors.length];
  },
  x: function(i) {
    return i * 50;
  }
});

var animation = TweenMax.to(".box", size, {  // size = time
  ease: Linear.easeNone,
  paused: true,
  x: "+=500", //move each box 500px to right
  modifiers: {
    x: function(x) {
      return x % 500; //force x value to be between 0 and 500 using modulus
    }
  },
  repeat: -1
});

Draggable.create('#proxy', {
  type: "x",
  trigger: document.documentElement,
  throwProps: true,
  onDrag: updateProgress,
  onThrowUpdate: updateProgress,
  onThrowComplete:updateProgress,
  snap: {x: function(value) {
    return Math.round(value / 50) * 50;
   }}
});



function updateProgress() {  
  animation.seek(this.x);
}


 

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

  • Like 2
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...