_mixin.scss 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. @mixin center($width: null, $height: null) {
  2. position: absolute;
  3. top: 50%;
  4. left: 50%;
  5. @if not $width and not $height {
  6. transform: translate(-50%, -50%);
  7. }
  8. @else if $width and $height {
  9. width: $width;
  10. height: $height;
  11. margin: -($height / 2) #{0 0} -($width / 2);
  12. }
  13. @else if not $height {
  14. width: $width;
  15. margin-left: -($width / 2);
  16. transform: translateY(-50%);
  17. }
  18. @else {
  19. height: $height;
  20. margin-top: -($height / 2);
  21. transform: translateX(-50%);
  22. }
  23. }
  24. @mixin opacity($opacity) {
  25. opacity: $opacity;
  26. $opacity-ie: $opacity * 100;
  27. filter: alpha(opacity=$opacity-ie);
  28. }
  29. @mixin ell() {
  30. //
  31. overflow: hidden;
  32. -ms-text-overflow: ellipsis;
  33. text-overflow: ellipsis;
  34. white-space: nowrap;
  35. }
  36. //多行超出省略号
  37. @mixin ell2() {
  38. word-break: break-all;
  39. text-overflow: ellipsis;
  40. display: -webkit-box;
  41. -webkit-box-orient: vertical;
  42. -webkit-line-clamp: 2;
  43. overflow: hidden;
  44. }
  45. //.arrow{
  46. // @include arrow(bottom,10px,#F00);
  47. //
  48. @mixin arrow($direction, $size, $color) {
  49. width: 0;
  50. height: 0;
  51. line-height: 0;
  52. font-size: 0;
  53. overflow: hidden;
  54. border-width: $size;
  55. cursor: pointer;
  56. @if $direction==top {
  57. border-style: dashed dashed solid dashed;
  58. border-color: transparent transparent $color transparent;
  59. border-top: none;
  60. }
  61. @else if $direction==bottom {
  62. border-style: solid dashed dashed dashed;
  63. border-color: $color transparent transparent transparent;
  64. border-bottom: none;
  65. }
  66. @else if $direction==right {
  67. border-style: dashed dashed dashed solid;
  68. border-color: transparent transparent transparent $color;
  69. border-right: none;
  70. }
  71. @else if $direction==left {
  72. border-style: dashed solid dashed dashed;
  73. border-color: transparent $color transparent transparent;
  74. border-left: none;
  75. }
  76. }
  77. // clearfix
  78. @mixin clr {
  79. &:after {
  80. clear: both;
  81. content: '.';
  82. display: block;
  83. height: 0;
  84. line-height: 0;
  85. overflow: hidden;
  86. }
  87. *height: 1%;
  88. }
  89. /*渐变(从上到下)*/
  90. @mixin linear-gradient($direction:bottom, $color1:transparent, $color2:#306eff, $color3:transparent) {
  91. //background: -webkit-linear-gradient($direction,$colorTop, $colorCenter, $colorBottom); /* Safari 5.1 - 6.0 */
  92. background: -o-linear-gradient($direction, $color1, $color2, $color3);
  93. /* Opera 11.1 - 12.0 */
  94. background: -moz-linear-gradient($direction, $color1, $color2, $color3);
  95. /* Firefox 3.6 - 15 */
  96. background: linear-gradient(to $direction, $color1, $color2, $color3);
  97. /* 标准的语法 */
  98. }
  99. /* 行高 */
  100. @mixin line-height($height:30px, $line-height:30px) {
  101. @if ($height !=null) {
  102. height: $height;
  103. }
  104. @if ($line-height !=null) {
  105. line-height: $line-height;
  106. }
  107. }
  108. /* 定义滚动条样式 圆角和阴影不需要则传入null */
  109. @mixin scrollBar($width:10px, $height:10px, $outColor:$bgColor, $innerColor:$bgGrey, $radius:5px, $shadow:null) {
  110. /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  111. &::-webkit-scrollbar {
  112. width: $width;
  113. height: $height;
  114. background-color: $outColor;
  115. }
  116. /*定义滚动条轨道 内阴影+圆角*/
  117. &::-webkit-scrollbar-track {
  118. @if ($shadow !=null) {
  119. -webkit-box-shadow: $shadow;
  120. }
  121. @if ($radius !=null) {
  122. border-radius: $radius;
  123. }
  124. background-color: $outColor;
  125. }
  126. /*定义滑块 内阴影+圆角*/
  127. &::-webkit-scrollbar-thumb {
  128. @if ($shadow !=null) {
  129. -webkit-box-shadow: $shadow;
  130. }
  131. @if ($radius !=null) {
  132. border-radius: $radius;
  133. }
  134. background-color: $innerColor;
  135. border: 1px solid $innerColor;
  136. }
  137. }
  138. /* css3动画 默认3s宽度到200px */
  139. @mixin animation($from:(width:0px), $to:(width:200px), $name:mymove, $animate:mymove 2s 1 linear infinite) {
  140. -webkit-animation: $animate;
  141. -o-animation: $animate;
  142. animation: $animate;
  143. @keyframes #{$name} {
  144. from {
  145. @each $key,
  146. $value in $from {
  147. #{$key}: #{$value};
  148. }
  149. }
  150. to {
  151. @each $key,
  152. $value in $to {
  153. #{$key}: #{$value};
  154. }
  155. }
  156. }
  157. @-webkit-keyframes #{$name} {
  158. from {
  159. @each $key,
  160. $value in $from {
  161. $key: $value;
  162. }
  163. }
  164. to {
  165. @each $key,
  166. $value in $to {
  167. $key: $value;
  168. }
  169. }
  170. }
  171. }