Jump to content
Search Community

kill(), but check the instance exists first?

mimeartist

Go to solution Solved by Jonathan,

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

Posted

Is there a way of checking a draggable instance of a div exists?

 

I'm using kill() for something but it is throwing an error if I try and kill something that's not there, so my question is, can i check for the draggable without getting an error?

Posted

Thanks Jonathan,

 

it's not the element I need to check for, it's whether it has a draggable assigned to it... ideally I'd keep a track on them all but hoping there is a simple way to just check if the draggable exists first as it's not a certainty that some items are draggable.

  • Solution
Posted

Im sure Jack and Carl could give a better answer regarding checking if your Draggable instance exists.

 

But in the meantime .. Have you tried checking if it is an object:

:

var myDraggable;

// instance does not exist - outputs 'undefined' 
console.log(myDraggable);

// create GSAP Draggable instance
myDraggable = Draggable.create("#yourID", {
	type:"y"
});

// do some code stuff here

// check if myDraggable instance is an object
if(typeof myDraggable === 'object'){
    // instance exists
    console.log("myDraggable instance exists");
}

:

If this doesn't help could you please provide a limited example of what your are seeing in a codepen example. This way we can better help you by seeing your code in context.

 

How to setup a codepen example.

 

Thanks!

  • Like 2
Posted

I'm such an idiot... I'd done this... and it wasn't working... turned out I was typing 'underfined'

 

if (typeof Draggable.get($(tempClip))!='undefined'){

Draggable.get($(tempClip)).kill();
}
  • Like 2

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...