mixin.scss 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. %fullMixin {
  2. top: 0;
  3. right: 0;
  4. bottom: 0;
  5. left: 0;
  6. }
  7. %colorTextMixin {
  8. position: relative;
  9. overflow: hidden;
  10. // 因为colorTextMixin会先编译,它生成的css在colorText的前面,
  11. // 所以colorTextMixin的background-clip会被后面的colorText的background覆盖,
  12. // 因此colorTextMixin的background-clip得使用!important
  13. -webkit-background-clip: text !important;
  14. background-clip: text !important;
  15. color: transparent;
  16. }
  17. %multiEllipsisMixin {
  18. display: -webkit-box;
  19. overflow: hidden;
  20. -webkit-box-orient: vertical;
  21. text-overflow: -o-ellipsis-lastline;
  22. text-overflow: ellipsis;
  23. word-break: break-all;
  24. }
  25. %arrowMixin {
  26. position: relative;
  27. display: inline-block;
  28. &::after {
  29. position: absolute;
  30. top: 0;
  31. left: 0;
  32. width: inherit;
  33. height: inherit;
  34. border-width: 0 0 1px 1px;
  35. border-style: solid;
  36. border-color: inherit;
  37. background-color: inherit;
  38. content: '';
  39. transition: all 0.3s ease;
  40. }
  41. }
  42. // 充满屏幕
  43. @mixin full($position: absolute) {
  44. position: $position;
  45. @extend %fullMixin;
  46. }
  47. // 多行省略号
  48. @mixin multiEllipsis($row: 2) {
  49. @extend %multiEllipsisMixin;
  50. -webkit-line-clamp: ($row);
  51. line-clamp: ($row);
  52. }
  53. // 箭头
  54. @mixin arrow($position, $size: 10px) {
  55. width: $size;
  56. height: $size;
  57. @extend %arrowMixin;
  58. &::after {
  59. @if $position == 'left' {
  60. transform: rotate(45deg);
  61. }
  62. @if $position == 'right' {
  63. transform: rotate(-135deg);
  64. }
  65. @if $position == 'top' {
  66. transform: rotate(135deg);
  67. }
  68. @if $position == 'bottom' {
  69. transform: rotate(-45deg);
  70. }
  71. }
  72. }
  73. // 颜色文字,用法:@include colorText('#8a2387, #f27121', 'to left');
  74. @mixin colorText($color: '#8a2387, #e94057, #f27121', $position: 'to left') {
  75. background: -webkit-linear-gradient(
  76. #{$position},
  77. #{$color}
  78. ); /* Chrome 10-25, Safari 5.1-6 */
  79. background: linear-gradient(
  80. #{$position},
  81. #{$color}
  82. ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  83. @extend %colorTextMixin;
  84. }
  85. // 设置背景,用法:@include colorText('#8a2387, #f27121', 'to left');
  86. @mixin setBackground(
  87. $url,
  88. $x: center,
  89. $y: center,
  90. $repeat: no-repeat,
  91. $size: contain
  92. ) {
  93. background-image: #{url($url)};
  94. background-position: $x $y;
  95. background-size: $size;
  96. background-repeat: $repeat;
  97. }
  98. // 设置定位位置(默认absolute定位)
  99. @mixin setPosition(
  100. $position: absolute,
  101. $top: initial,
  102. $right: initial,
  103. $bottom: initial,
  104. $left: initial
  105. ) {
  106. position: $position;
  107. top: $top;
  108. right: $right;
  109. bottom: $bottom;
  110. left: $left;
  111. }
  112. // 彩色阴影
  113. @mixin colorShadow($background: skyblue) {
  114. position: relative;
  115. width: 200px;
  116. height: 200px;
  117. img {
  118. position: absolute;
  119. top: 0;
  120. left: 0;
  121. z-index: 2;
  122. width: 100%;
  123. height: 100%;
  124. border-radius: 100%;
  125. object-fit: cover;
  126. }
  127. &::after {
  128. position: absolute;
  129. top: 10%;
  130. left: 0;
  131. z-index: 1;
  132. width: 100%;
  133. height: 100%;
  134. border-radius: 100%;
  135. background: $background;
  136. background-position: center;
  137. background-size: cover;
  138. background-repeat: no-repeat;
  139. content: '';
  140. filter: blur(10px) brightness(80%) opacity(0.8);
  141. transform: scale(0.95);
  142. }
  143. }
  144. // 黑色阴影
  145. @mixin shadow($color: black) {
  146. // box-shadow: 水平偏移 垂直偏移 模糊半径 阴影颜色;
  147. box-shadow: 0 10px 10px rgba(0, 0, 0, 0.1), 0 10px 10px #{$color};
  148. }
  149. // 高斯模糊/毛玻璃效果
  150. @mixin blur($px: 5px) {
  151. filter: blur($px);
  152. }