Jump to content
Search Community

vuejs problem to init draggable.create(classname)

mindthegap test
Moderator Tag

Go to solution Solved by ZachSaucier,

Recommended Posts

I done a few things with gsap in vuejs to animate simple html or svg elements.

 

Now I tried to make an drag an drop game based on this tutorial:

 

 

when I use the import Draggable I got in the VSC console the fllowing message: "export 'Draggable' was not found in 'gsap'

and I the browser console: [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'create' of undefined"  

 

here's the code

 

<script>
import {gsap , Draggable} from 'gsap'  

export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  mounted() {
    

    Draggable.create(".icon", {
       bounds:"svg",
       onPress: function(){
         console.log(this.target);
       },
       onDrag: function() {
         if (this.hitTest("#bag")) {
           gsap.to(this.target, {duration: 0.6, opacity:0, scale:0, svgOrigin:"675 143"});
         }
       }
     });
  },
}
</script>

 

where's my fault?

 

Link to comment
Share on other sites

  • Solution

Hey mindthegap and welcome to the GreenSock forums. 

 

As covered in the GSAP installation docs, Draggable is a GSAP plugin that you need to include in addition to the GSAP core. So you should just need to import GSAP and Draggable like this (as covered in the installation docs):

import { gsap } from "gsap";
import { Draggable } from "gsap/Draggable";

// Put this inside of your mounted function
gsap.registerPlugin(Draggable);

 

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

Just had to check that Draggables were included in the stuff that context collects up, and yes, they are 🥳

So back to your question, no, it's not "necessary"- as in - you can just kill or clean up your animations yourself. But it makes life easier.

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

context basically groups all your GSAP animations, scrollTriggers and (in this case) Draggables so that you can kill these just by calling context.revert()

 

  • Like 2
Link to comment
Share on other sites

Thanks for all you revert backs. 
you solution worked for me.

Request if you can update the stackblitz by creating a dropzone where I can move object from one to another list.

https://stackblitz.com/edit/vue-plgvav?file=src/App.vue

 

few other questions:

1. how to get dragged elements object as I wanted to move that in to another list.

2. holding right click is also let the element drag, how to disable that.

3. can we also use vue-draggable with gsap draggable

Link to comment
Share on other sites

Hi,

 

As much as we love helping users We have limited time resources in the forums, so we can't tackle lists of requests for our users.

 

You might want to have a look at this:

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

 

As for your questions:

  1. This will depend if you want to duplicate them or re-parent them. In both cases I'd use state management to keep elements in one or two lists and render the DOM accordingly using a v-for directive.
  2. You can check the event type in the onClick callback and if it is the secondary mouse button stop your code or use the allow the context  menu config option from the Draggable Docs:
    allowContextMenu
    Boolean - If true, Draggable will allow context menus (like if a user right-clicks or long-touches). Normally this is suppressed because it can get in the way of dragging (especially on touch devices). Default: false.
  3. I have no idea how that particular library works. I guess you could use them in different components but I'd test before using both on prduction.

Happy Tweening!

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