transition-transform.uvue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <view style="flex: 1;">
  3. <view id="v" class="popup" @click="open"></view>
  4. <view class="test"></view>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. transform: 'scale(0.6) translate(-50%, -50%)',
  12. }
  13. },
  14. onLoad() {
  15. },
  16. methods: {
  17. open() {
  18. if ('scale(0.6) translate(-50%, -50%)' == this.transform) {
  19. this.transform = 'scale(1) translate(-50%, -50%)';
  20. } else {
  21. this.transform = 'scale(0.6) translate(-50%, -50%)';
  22. }
  23. uni.getElementById('v')?.style.setProperty('transform', this.transform)
  24. }
  25. }
  26. }
  27. </script>
  28. <style>
  29. .popup {
  30. position: fixed;
  31. left: 50%;
  32. top: 50%;
  33. width: 200px;
  34. height: 200px;
  35. background: red;
  36. transition-duration: 300ms;
  37. transition-property: transform, opacity;
  38. transition-timing-function: ease;
  39. overflow: visible;
  40. transform-origin: left top;
  41. transform: scale(0.6) translate(-50%, -50%);
  42. }
  43. .test {
  44. position: fixed;
  45. left: 50%;
  46. top: 50%;
  47. width: 200px;
  48. height: 200px;
  49. background: rgba(0, 0, 0, 0.5);
  50. }
  51. </style>