joystick.vue 622 B

12345678910111213141516171819202122232425262728293031
  1. <template>
  2. <div><div></div></div>
  3. </template>
  4. <script>
  5. export default {
  6. mounted() {
  7. const joystick = nipplejs.create({
  8. zone: this.$el.children[0],
  9. position: { left: "50%", top: "50%" },
  10. dynamicPage: true,
  11. ...this.options,
  12. });
  13. joystick.on("start", (e) => this.$emit("start", e));
  14. joystick.on("move", (_, data) => this.$emit("move", { data }));
  15. joystick.on("end", (e) => this.$emit("end", e));
  16. },
  17. props: {
  18. options: Object,
  19. },
  20. };
  21. </script>
  22. <style scoped>
  23. :scope > div {
  24. background-color: AliceBlue;
  25. width: 10em;
  26. height: 10em;
  27. position: relative;
  28. }
  29. </style>