uni-events-helper-wx
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.4 KiB

3 years ago
  1. // flex(主轴,交叉轴,方向,换行,多轴线对齐)
  2. @mixin flex($justify: null, $align: null, $direction: null, $warp: null, $warpAlign: null) {
  3. display: flex;
  4. @if $direction != null {
  5. @include flex-direction($direction);
  6. }
  7. @if $justify != null {
  8. @include flex-justify($justify);
  9. }
  10. @if $align != null {
  11. @include flex-align($align);
  12. }
  13. @if $warp != null {
  14. @include flex-warp($warp);
  15. }
  16. @if $warpAlign != null {
  17. @include flex-warpAlign($warpAlign);
  18. }
  19. }
  20. // flex-self(对齐,(布满||固定),顺序)
  21. @mixin flex-self($flex: null, $align: null, $order: null){
  22. @if $flex != null {
  23. @if $flex == full {
  24. flex: auto;
  25. } @else if $flex == keep {
  26. flex: none;
  27. } @else {
  28. @include flexError($flex, 'flex-self');
  29. }
  30. }
  31. @if $align != null {
  32. @include flex-selfAlign($align);
  33. }
  34. @if $order != null {
  35. @include flex-order($order);
  36. }
  37. }
  38. // flex错误提示
  39. @mixin flexError($param, $type) {
  40. position: relative;
  41. background-color: #ff3c00 !important;
  42. overflow: hidden;
  43. &::after {
  44. position: absolute;
  45. bottom: 0;
  46. right: 0;
  47. padding: 0.5em;
  48. color: #ff3c00 !important;
  49. background-color: white !important;
  50. font-size: 12px;
  51. content: 'ErrorParam: #{$param} in #{$type}';
  52. }
  53. }
  54. // 项目的排列方向
  55. @mixin flex-direction($direction: row) {
  56. @if $direction == column {
  57. flex-direction: column;
  58. } @else if $direction == row {
  59. flex-direction: row;
  60. } @else if $direction == row-reverse {
  61. flex-direction: row-reverse;
  62. } @else if $direction == column-reverse {
  63. flex-direction: column-reverse;
  64. } @else {
  65. @include flexError($direction, 'flex-direction');
  66. }
  67. }
  68. // 主轴上的对齐方式
  69. @mixin flex-justify($justify: start) {
  70. @if $justify == start {
  71. justify-content: start;
  72. } @else if $justify == center {
  73. justify-content: center;
  74. } @else if $justify == end {
  75. justify-content: flex-end;
  76. } @else if $justify == between {
  77. justify-content: space-between;
  78. } @else if $justify == around {
  79. justify-content: space-around;
  80. } @else {
  81. @include flexError($justify, 'flex-justify');
  82. }
  83. }
  84. // 交叉轴上的对齐方式
  85. @mixin flex-align($align: top) {
  86. @if $align == top {
  87. align-items: flex-start;
  88. } @else if $align == center {
  89. align-items: center;
  90. } @else if $align == bottom {
  91. align-items: flex-end;
  92. } @else {
  93. @include flexError($align, 'flex-align');
  94. }
  95. }
  96. // 换行
  97. @mixin flex-warp($warp: wrap) {
  98. @if $warp == wrap {
  99. flex-wrap: wrap;
  100. } @else if $warp == nowrap {
  101. flex-wrap: nowrap;
  102. } @else if $warp == wrap-reverse {
  103. flex-wrap: wrap-reverse;
  104. } @else {
  105. @include flexError($warp, 'flex-wrap');
  106. }
  107. }
  108. // 换行多根轴线的对齐方式,如果项目只有一根轴线,该属性不起作用
  109. @mixin flex-warpAlign($align: stretch) {
  110. @if $align == stretch {
  111. align-content: stretch;
  112. } @else if $align == top {
  113. align-content: flex-start;
  114. } @else if $align == center {
  115. align-content: center;
  116. } @else if $align == bottom {
  117. align-content: flex-end;
  118. } @else if $align == between {
  119. align-content: space-between;
  120. } @else if $align == around {
  121. align-content: space-around;
  122. } @else {
  123. @include flexError($align, 'flex-wrapAlign');
  124. }
  125. }
  126. // 单个项目有与其他项目不一样的对齐方式
  127. @mixin flex-selfAlign($align: auto){
  128. @if $align == auto {
  129. align-self: auto;
  130. } @else if $align == top {
  131. align-self: flex-start;
  132. } @else if $align == center {
  133. align-self: center;
  134. } @else if $align == bottom {
  135. align-self: flex-end;
  136. } @else if $align == baseline {
  137. align-self: baseline ;
  138. } @else if $align == stretch {
  139. align-self: stretch;
  140. } @else {
  141. @include flexError($align, 'flex-self-align');
  142. }
  143. }
  144. // 项目的排列顺序,数值越小,排列越靠前,默认为0
  145. @mixin flex-order($order: 0){
  146. @if $order == round($order) {
  147. order: $order;
  148. } @else {
  149. @include flexError($order, 'flex-self-order');
  150. }
  151. }