css-float-ball.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="float-ball-wrap" :style="{zIndex}">
  3. <movable-area class="float-ball-movable-area">
  4. <!--悬浮球主体-->
  5. <movable-view :x="value.x" :y="value.y" class="float-ball" direction="all" inertia :animation="false"
  6. @change="drag" out-of-bounds>
  7. <!--悬浮球外部插槽-->
  8. <slot></slot>
  9. </movable-view>
  10. </movable-area>
  11. </view>
  12. </template>
  13. <script>
  14. import {debounce} from './util'
  15. export default {
  16. name: 'css-float-ball',
  17. props: {
  18. zIndex: {
  19. type: [String, Number],
  20. default: 999,
  21. },
  22. autoBox: {
  23. type: [Boolean],
  24. default: true,
  25. },
  26. value: {
  27. type: Object,
  28. required: true,
  29. default() {
  30. return {x: 360, y: 256}
  31. }
  32. },
  33. //防抖时长
  34. debounce:{
  35. type: Number,
  36. default:128,
  37. },
  38. },
  39. computed: {},
  40. data() {
  41. return {}
  42. },
  43. methods: {
  44. /**
  45. * 拖动时,更新globalData,也可以用vuex替代
  46. * @param e
  47. */
  48. drag(e) {
  49. const _this = this;
  50. debounce(function () {
  51. getApp().globalData.globalFloatBallPosition = e.detail;
  52. }, _this.debounce)
  53. },
  54. },
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. @import "index";
  59. .default-icon-hover {
  60. opacity: 0.6;
  61. }
  62. </style>