pointer-events.uvue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <view>
  6. <view class="container1">
  7. <text>控制父视图pointer-events打开时可以点击</text>
  8. <switch :checked="true" @change="onChange1" />
  9. </view>
  10. <view class="container" :style="{ 'pointer-events': pointerEvents1 }">
  11. <text class="text">点击修改宽度</text>
  12. <view class="base-style transition-width" id="widthOrHeight" @click="changeWidthOrHeight"></view>
  13. </view>
  14. <view class="container1">
  15. <text>控制遮罩层pointer-events关闭时可以点击</text>
  16. <switch :checked="true" @change="onChange2" />
  17. </view>
  18. <view class="container">
  19. <text class="text">点击修改宽度(递增)</text>
  20. <view class="width-progress transition-width" id="widthProgress" @click="changeWidthProgress"></view>
  21. <view class="mask" :style="{ 'pointer-events': pointerEvents2 }"></view>
  22. </view>
  23. </view>
  24. <!-- #ifdef APP -->
  25. </scroll-view>
  26. <!-- #endif -->
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. isTranstionWidthOrHeight: false,
  33. widthOrHeight: null as UniElement | null,
  34. widthProgress: null as UniElement | null,
  35. progressWidth: 200,
  36. pointerEvents1: 'auto',
  37. pointerEvents2: 'auto',
  38. }
  39. },
  40. onReady() {
  41. this.widthOrHeight = uni.getElementById("widthOrHeight")
  42. this.widthProgress = uni.getElementById("widthProgress")
  43. },
  44. methods: {
  45. changeWidthOrHeight() {
  46. this.widthOrHeight?.style?.setProperty("width", this.isTranstionWidthOrHeight
  47. ? '200px'
  48. : '300px')
  49. this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
  50. },
  51. changeWidthProgress() {
  52. this.progressWidth += 20
  53. this.widthProgress?.style?.setProperty("width", this.progressWidth + 'px')
  54. },
  55. onChange1(e : UniSwitchChangeEvent) {
  56. this.pointerEvents1 = e.detail.value ? 'auto' : 'none'
  57. },
  58. onChange2(e : UniSwitchChangeEvent) {
  59. this.pointerEvents2 = e.detail.value ? 'auto' : 'none'
  60. }
  61. }
  62. }
  63. </script>
  64. <style>
  65. .container1 {
  66. margin: 7px 0px 7px 7px;
  67. display: flex;
  68. flex-direction: row;
  69. justify-content: space-between;
  70. align-items: center;
  71. }
  72. .container {
  73. margin: 7px;
  74. background-color: white;
  75. }
  76. .text {
  77. margin-top: 10px;
  78. margin-bottom: 16px;
  79. }
  80. .base-style {
  81. width: 200px;
  82. height: 200px;
  83. background-color: brown;
  84. }
  85. .width-progress {
  86. width: 200px;
  87. height: 200px;
  88. background-color: brown;
  89. }
  90. .transition-width {
  91. transition-property: width;
  92. transition-duration: 1s;
  93. }
  94. .mask {
  95. position: absolute;
  96. bottom: 0;
  97. left: 0;
  98. width: 100%;
  99. height: 200px;
  100. background-color: rgba(0, 0, 0, 0.5);
  101. }
  102. </style>