transform-origin.uvue 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <view style="flex:1">
  3. <view ref="transformView" class="view" @click="changetransform"></view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. count: 0
  11. }
  12. },
  13. methods: {
  14. changetransform() {
  15. var element = this.$refs["transformView"] as UniElement | null
  16. if (this.count == 0) {
  17. element?.style.setProperty("transform-origin", "60px 60px")
  18. element?.style.setProperty("transform", "scale(1)")
  19. }
  20. else if (this.count == 1) {
  21. element?.style.setProperty("transform-origin", "100% 0%")
  22. element?.style.setProperty("transform", "rotate(-20deg)")
  23. }
  24. this.count++
  25. }
  26. }
  27. }
  28. </script>
  29. <style>
  30. .view {
  31. width: 100px;
  32. height: 100px;
  33. transform-origin: 10px 10px;
  34. background-color: aqua;
  35. transform: translate(50px, 50px) scale(2);
  36. border-width: 1px;
  37. border-color: black;
  38. border-style: solid;
  39. }
  40. </style>