QMUI_Sass 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.gitignore +66 -0
- data/.npmignore +2 -0
- data/.travis.yml +14 -0
- data/Gemfile +6 -0
- data/LICENSE +38 -0
- data/QMUI_Sass.gemspec +30 -0
- data/README.md +55 -0
- data/Rakefile +9 -0
- data/_var.scss +120 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/QMUI_Sass.rb +6 -0
- data/lib/QMUI_Sass/version.rb +3 -0
- data/package.json +26 -0
- data/qmui/_function.scss +54 -0
- data/qmui/_qmui.scss +32 -0
- data/qmui/_reset.scss +84 -0
- data/qmui/mixin/_adaptation.scss +236 -0
- data/qmui/mixin/_mixin.scss +13 -0
- data/qmui/mixin/tool/_calculate.scss +232 -0
- data/qmui/mixin/tool/_effect.scss +189 -0
- data/qmui/mixin/tool/_enhance.scss +44 -0
- data/qmui/mixin/tool/_tool.scss +16 -0
- data/stylelint.config.js +133 -0
- data/yarn.lock +3546 -0
- metadata +99 -0
data/qmui/_function.scss
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
@charset "utf-8";
|
2
|
+
/**
|
3
|
+
* _function.scss
|
4
|
+
* @author Kayo
|
5
|
+
* @date 2014-11-17
|
6
|
+
*/
|
7
|
+
|
8
|
+
.qui_txtNormal {
|
9
|
+
font-weight: normal !important;
|
10
|
+
}
|
11
|
+
|
12
|
+
.qui_txtBold {
|
13
|
+
font-weight: bold !important;
|
14
|
+
}
|
15
|
+
|
16
|
+
.qui_txtLeft {
|
17
|
+
text-align: left !important;
|
18
|
+
}
|
19
|
+
|
20
|
+
.qui_txtRight {
|
21
|
+
text-align: right !important;
|
22
|
+
}
|
23
|
+
|
24
|
+
.qui_txtUnderline {
|
25
|
+
text-decoration: underline !important;
|
26
|
+
}
|
27
|
+
|
28
|
+
.qui_txtUnderlineNone {
|
29
|
+
text-decoration: none !important;
|
30
|
+
}
|
31
|
+
|
32
|
+
.qui_txtOverflow {
|
33
|
+
@extend %text_ellipsis;
|
34
|
+
}
|
35
|
+
|
36
|
+
.qui_clear {
|
37
|
+
@extend %clear;
|
38
|
+
}
|
39
|
+
|
40
|
+
.qui_txtNowrap {
|
41
|
+
white-space: nowrap !important;
|
42
|
+
}
|
43
|
+
|
44
|
+
.qui_layoutLeft {
|
45
|
+
float: left !important;
|
46
|
+
}
|
47
|
+
|
48
|
+
.qui_layoutRight {
|
49
|
+
float: right !important;
|
50
|
+
}
|
51
|
+
|
52
|
+
.qui_displayNone {
|
53
|
+
display: none !important;
|
54
|
+
}
|
data/qmui/_qmui.scss
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Tencent is pleased to support the open source community by making QMUI Web available.
|
3
|
+
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
|
4
|
+
* Licensed under the MIT License (the "License"); you may not use this file except in compliance
|
5
|
+
* with the License. You may obtain a copy of the License at
|
6
|
+
*
|
7
|
+
* http://opensource.org/licenses/MIT
|
8
|
+
*
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
|
10
|
+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
11
|
+
* either express or implied. See the License for the specific language governing permissions and
|
12
|
+
* limitations under the License.
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
@charset "utf-8";
|
17
|
+
/**
|
18
|
+
* _qmui.scss QMUI 总样式文件
|
19
|
+
* @author Kayo
|
20
|
+
* @date 2014-10-31
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
|
24
|
+
|
25
|
+
// 常用 mixin 封装
|
26
|
+
@import "mixin/_mixin";
|
27
|
+
|
28
|
+
// CSS Reset
|
29
|
+
@import "_reset";
|
30
|
+
|
31
|
+
// 常用样式(原子类)
|
32
|
+
@import "_function";
|
data/qmui/_reset.scss
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
@charset "utf-8";
|
2
|
+
/**
|
3
|
+
* _reset.scss
|
4
|
+
* @author Kayo
|
5
|
+
* @date 2014-10-30
|
6
|
+
*
|
7
|
+
* #reset
|
8
|
+
* #html5
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* #reset */
|
12
|
+
body, dl, dd, h1, h2, h3, h4, h5, h6, p, pre, form, fieldset, legend {
|
13
|
+
margin: 0;
|
14
|
+
}
|
15
|
+
|
16
|
+
ul, ol, fieldset {
|
17
|
+
margin: 0;
|
18
|
+
padding: 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
th, td {
|
22
|
+
padding: 0;
|
23
|
+
}
|
24
|
+
|
25
|
+
table {
|
26
|
+
font-size: inherit;
|
27
|
+
}
|
28
|
+
|
29
|
+
fieldset, img {
|
30
|
+
border: 0;
|
31
|
+
}
|
32
|
+
|
33
|
+
ul, ol, li {
|
34
|
+
list-style: none;
|
35
|
+
}
|
36
|
+
|
37
|
+
body {
|
38
|
+
font-size: $common_fontSize;
|
39
|
+
line-height: 1.5;
|
40
|
+
background: $common_body_background;
|
41
|
+
color: $common_body_color;
|
42
|
+
}
|
43
|
+
|
44
|
+
h1, h2, h3, h4 {
|
45
|
+
font-size: 18px;
|
46
|
+
font-weight: normal;
|
47
|
+
}
|
48
|
+
|
49
|
+
body, input, textarea, select, button {
|
50
|
+
font-family: $common_fontFamily;
|
51
|
+
outline: none;
|
52
|
+
// stylelint-disable
|
53
|
+
// For Webkit kernel on mobile
|
54
|
+
-webkit-text-size-adjust: none;
|
55
|
+
// stylelint-enable
|
56
|
+
}
|
57
|
+
|
58
|
+
input, textarea, select, button {
|
59
|
+
font-size: inherit; // form control's default font in webkit is "-webkit-small-control"
|
60
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove widget tap highlighted in mobile safari
|
61
|
+
}
|
62
|
+
|
63
|
+
a {
|
64
|
+
color: $common_color_link;
|
65
|
+
text-decoration: none;
|
66
|
+
-webkit-tap-highlight-color: $common_color_linkTapHighlight;
|
67
|
+
}
|
68
|
+
|
69
|
+
:focus {
|
70
|
+
outline: none;
|
71
|
+
}
|
72
|
+
|
73
|
+
/* #html5 HTML5 元素的支持 */
|
74
|
+
article, aside, details,
|
75
|
+
figcaption, figure,
|
76
|
+
footer, header, hgroup,
|
77
|
+
main, nav, section,
|
78
|
+
summary {
|
79
|
+
display: block;
|
80
|
+
}
|
81
|
+
|
82
|
+
audio, canvas, video {
|
83
|
+
display: inline-block;
|
84
|
+
}
|
@@ -0,0 +1,236 @@
|
|
1
|
+
@charset "UTF-8";
|
2
|
+
|
3
|
+
////
|
4
|
+
/// 平台与浏览器适配相关方法
|
5
|
+
/// @author Clear, Molice, Zhoon, Kayo,Jeff
|
6
|
+
/// @group 兼容性封装
|
7
|
+
/// @date 2014-08-19
|
8
|
+
////
|
9
|
+
|
10
|
+
/// 清除浮动
|
11
|
+
///
|
12
|
+
/// @group 布局
|
13
|
+
/// @name clear
|
14
|
+
%clear {
|
15
|
+
&:after {
|
16
|
+
clear: both;
|
17
|
+
content: ".";
|
18
|
+
display: block;
|
19
|
+
line-height: 0;
|
20
|
+
font-size: 0;
|
21
|
+
visibility: hidden;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
/// 单行省略号
|
26
|
+
///
|
27
|
+
/// @group 外观
|
28
|
+
/// @name text-ellipsis
|
29
|
+
%text-ellipsis {
|
30
|
+
overflow: hidden;
|
31
|
+
white-space: nowrap;
|
32
|
+
text-overflow: ellipsis;
|
33
|
+
word-break: break-all;
|
34
|
+
//在IE9的<td>中,如果之前已经设置了word-wrap:break-word,则这里的white-space:nowrap会失效,所以要在这里加上word-wrap:normal来以防万一
|
35
|
+
word-wrap: normal;
|
36
|
+
}
|
37
|
+
|
38
|
+
%text_ellipsis {
|
39
|
+
@extend %text-ellipsis;
|
40
|
+
}
|
41
|
+
|
42
|
+
/// 多行省略号
|
43
|
+
///
|
44
|
+
/// @group 外观
|
45
|
+
/// @name text-multiLine-ellipsis
|
46
|
+
/// @param {Number} $line - 文字的行数
|
47
|
+
/// @param {Measure} $lineHeight - 文字行高
|
48
|
+
/// @throw 不支持多行省略的浏览器降级处理为结尾处没有省略号,直接裁剪掉。
|
49
|
+
@mixin text-multiLine-ellipsis($line: 2, $lineHeight: 20px) {
|
50
|
+
line-height: $lineHeight;
|
51
|
+
overflow: hidden;
|
52
|
+
height: $lineHeight * $line;
|
53
|
+
// stylelint-disable
|
54
|
+
display: -webkit-box;
|
55
|
+
display: -moz-box;
|
56
|
+
text-overflow: ellipsis;
|
57
|
+
-webkit-line-clamp: $line;
|
58
|
+
-moz-line-clamp: $line;
|
59
|
+
line-clamp: $line;
|
60
|
+
-webkit-box-orient: vertical;
|
61
|
+
-moz-box-orient: vertical;
|
62
|
+
// stylelint-enable
|
63
|
+
box-orient: vertical;
|
64
|
+
}
|
65
|
+
|
66
|
+
/// 在长单词或 URL 地址内部进行换行,适用于以中文为主混有英文的文字排版
|
67
|
+
///
|
68
|
+
/// @group 外观
|
69
|
+
/// @name text-breakWord
|
70
|
+
%text-breakWord {
|
71
|
+
word-wrap: break-word;
|
72
|
+
word-break: break-word;
|
73
|
+
}
|
74
|
+
|
75
|
+
%text_breakWord {
|
76
|
+
@extend %text-breakWord;
|
77
|
+
}
|
78
|
+
|
79
|
+
/// 适配多倍屏的 CSS 选择器
|
80
|
+
///
|
81
|
+
/// @group 设备适配
|
82
|
+
/// @name screenResolution
|
83
|
+
/// @param {Number} $num - 需要适配的屏幕倍数
|
84
|
+
@mixin screenResolution($num) {
|
85
|
+
@media (-webkit-min-device-pixel-ratio: $num), (min--moz-device-pixel-ratio: $num), (min-device-pixel-ratio: $num), (min-resolution: #{$num}dppx), (min-resolution: #{$num * 96}dpi) {
|
86
|
+
@content;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
/// 适配 IE 10 及以上版本的 CSS 选择器,需要针对 IE10 或以上版本的样式可以写在这里
|
91
|
+
///
|
92
|
+
/// @group 设备适配
|
93
|
+
/// @name screenForIE10AndLater
|
94
|
+
@mixin screenForIE10AndLater {
|
95
|
+
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
|
96
|
+
@content;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/// 单独适配 IE 8 CSS 选择器,需要仅针对 IE 8 的样式可以写在这里
|
101
|
+
///
|
102
|
+
/// @group 设备适配
|
103
|
+
/// @name forIE8
|
104
|
+
@mixin forIE8 {
|
105
|
+
@media \0screen {
|
106
|
+
@content;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
/// 单独适配 IE 9 CSS 选择器,需要仅针对 IE 9(不包括 IE 10 等更高版本) 的样式可以写在这里
|
111
|
+
///
|
112
|
+
/// @group 设备适配
|
113
|
+
/// @name forIE9
|
114
|
+
@mixin forIE9 {
|
115
|
+
@media all and (min-width: 0\0) and (min-resolution: .001dpcm) {
|
116
|
+
@content;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/// 半透明背景颜色
|
121
|
+
///
|
122
|
+
/// @group 外观
|
123
|
+
/// @name bgWithOpacity
|
124
|
+
/// @param {Color} $color - 背景色的颜色值
|
125
|
+
/// @param {Number} $alpha - 背景色的透明度
|
126
|
+
@mixin bgWithOpacity($color, $alpha) {
|
127
|
+
background-color: rgba($color, $alpha);
|
128
|
+
@include forIE8 {
|
129
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#{ie-hex-str(rgba($color, $alpha))}, endcolorstr=#{ie-hex-str(rgba($color, $alpha))});
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/// 跨浏览器的渐变背景,垂直渐变,自上而下
|
134
|
+
///
|
135
|
+
/// @group 外观
|
136
|
+
/// @name gradient-vertical
|
137
|
+
/// @param {Color} $start-color [#555] - 渐变的开始颜色
|
138
|
+
/// @param {Color} $end-color [#333] - 渐变的结束颜色
|
139
|
+
/// @param {Number} $start-percent [0%] - 渐变的开始位置,需要以百分号为单位
|
140
|
+
/// @param {Number} $end-percent [100%] - 渐变的结束位置,需要以百分号为单位
|
141
|
+
@mixin gradient-vertical($start-color: #555, $end-color: #333, $start-percent: 0%, $end-percent: 100%) {
|
142
|
+
background-image: linear-gradient(to bottom, $start-color $start-percent, $end-color $end-percent);
|
143
|
+
background-repeat: repeat-x;
|
144
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#{ie-hex-str($start-color)}", endColorstr="#{ie-hex-str($end-color)}", GradientType=0); // IE9 and down
|
145
|
+
}
|
146
|
+
|
147
|
+
/// 跨浏览器的渐变背景,水平渐变,自左而右
|
148
|
+
///
|
149
|
+
/// @group 外观
|
150
|
+
/// @name gradient-horizontal
|
151
|
+
/// @param {Color} $start-color [#555] - 渐变的开始颜色
|
152
|
+
/// @param {Color} $end-color [#333] - 渐变的结束颜色
|
153
|
+
/// @param {Number} $start-percent [0%] - 渐变的开始位置,需要以百分号为单位
|
154
|
+
/// @param {Number} $end-percent [100%] - 渐变的结束位置,需要以百分号为单位
|
155
|
+
@mixin gradient-horizontal($start-color: #555, $end-color: #333, $start-percent: 0%, $end-percent: 100%) {
|
156
|
+
background-image: linear-gradient(to right, $start-color $start-percent, $end-color $end-percent);
|
157
|
+
background-repeat: repeat-x;
|
158
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#{ie-hex-str($start-color)}", endColorstr="#{ie-hex-str($end-color)}", GradientType=1); // IE9 and down
|
159
|
+
}
|
160
|
+
|
161
|
+
/// 跨浏览器的渐变背景,带角度
|
162
|
+
///
|
163
|
+
/// @group 外观
|
164
|
+
/// @name gradient-on-axis
|
165
|
+
/// @param {Degree} $axis-degree [135deg] - 渐变的轴
|
166
|
+
/// @param {Color} $start-color [#555] - 渐变的开始颜色
|
167
|
+
/// @param {Color} $end-color [#333] - 渐变的结束颜色
|
168
|
+
/// @param {Number} $start-percent [0%] - 渐变的开始位置,需要以百分号为单位
|
169
|
+
/// @param {Number} $end-percent [100%] - 渐变的结束位置,需要以百分号为单位
|
170
|
+
@mixin gradient-on-axis($axis-degree: 0, $start-color: #555, $end-color: #333, $start-percent: 0%, $end-percent: 100%) {
|
171
|
+
background-image: linear-gradient($axis-degree, $start-color $start-percent, $end-color $end-percent);
|
172
|
+
background-repeat: repeat-x;
|
173
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#{ie-hex-str($start-color)}", endColorstr="#{ie-hex-str($end-color)}", GradientType=0); // IE9 and down
|
174
|
+
}
|
175
|
+
|
176
|
+
/// 跨浏览器的渐变背景,垂直渐变,自上而下,支持三个渐变点
|
177
|
+
///
|
178
|
+
/// @group 外观
|
179
|
+
/// @name gradient-vertical-threeColor
|
180
|
+
/// @param {Color} $start-color [#555] - 渐变的开始颜色
|
181
|
+
/// @param {Color} $middle-color [#444] - 渐变的中间颜色
|
182
|
+
/// @param {Color} $end-color [#333] - 渐变的结束颜色
|
183
|
+
/// @param {Number} $start-percent [0%] - 渐变的开始位置,需要以百分号为单位
|
184
|
+
/// @param {Number} $start-percent [50%] - 渐变的中间位置,需要以百分号为单位
|
185
|
+
/// @param {Number} $end-percent [100%] - 渐变的结束位置,需要以百分号为单位
|
186
|
+
@mixin gradient-vertical-threeColor($start-color: #555, $middle-color: #444, $end-color: #333, $start-percent: 0%, $middle-percent: 50%, $end-percent: 100%) {
|
187
|
+
background-image: linear-gradient(to bottom, $start-color $start-percent, $middle-color $middle-percent, $end-color $end-percent);
|
188
|
+
background-repeat: repeat-x;
|
189
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#{ie-hex-str($start-color)}", endColorstr="#{ie-hex-str($end-color)}", GradientType=0); // IE9 and down
|
190
|
+
}
|
191
|
+
|
192
|
+
/// 跨浏览器的渐变背景,水平渐变,自左而右
|
193
|
+
///
|
194
|
+
/// @group 外观
|
195
|
+
/// @name gradient-horizontal-threeColor
|
196
|
+
/// @param {Color} $start-color [#555] - 渐变的开始颜色
|
197
|
+
/// @param {Color} $middle-color [#444] - 渐变的中间颜色
|
198
|
+
/// @param {Color} $end-color [#333] - 渐变的结束颜色
|
199
|
+
/// @param {Number} $start-percent [0%] - 渐变的开始位置,需要以百分号为单位
|
200
|
+
/// @param {Number} $start-percent [50%] - 渐变的中间位置,需要以百分号为单位
|
201
|
+
/// @param {Number} $end-percent [100%] - 渐变的结束位置,需要以百分号为单位
|
202
|
+
@mixin gradient-horizontal-threeColor($start-color: #555, $middle-color: #444, $end-color: #333, $start-percent: 0%, $middle-percent: 50%, $end-percent: 100%) {
|
203
|
+
background-image: linear-gradient(to right, $start-color $start-percent, $middle-color $middle-percent, $end-color $end-percent);
|
204
|
+
background-repeat: repeat-x;
|
205
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#{ie-hex-str($start-color)}", endColorstr="#{ie-hex-str($end-color)}", GradientType=1); // IE9 and down
|
206
|
+
}
|
207
|
+
|
208
|
+
/// 基于渐变实现的垂直方向点画线
|
209
|
+
/// @throw 如果要实现的是一个物理像素粗细的线,建议放在一个单独的 DOM 上,方便加上 scale 来实现,否则就不需要顾虑直接用到任意 DOM 上即可,加上 background-position 控制位置,background-color / background-position 等属性必须在该 mixin 的 include 之后开始写。
|
210
|
+
///
|
211
|
+
/// @group 外观
|
212
|
+
/// @name gradient-vertical-dashed-line
|
213
|
+
/// @param {Number} $dash-dot-width [2px] - 点画线里点的尺寸
|
214
|
+
/// @param {Number} $dash-space-width [2px] - 点画线里点与点间隔尺寸
|
215
|
+
/// @param {Color} $dash-dot-color [$common_color_separator] - 点画线里点的颜色
|
216
|
+
/// @param {Number} $line-width [1px] - 点画线粗细
|
217
|
+
@mixin gradient-vertical-dashed-line($dash-dot-width: 2px, $dash-space-width: 2px, $dash-dot-color: $common_color_separator, $line-width: 1px) {
|
218
|
+
@include gradient-vertical-threeColor($start-color: $dash-dot-color, $middle-color: $dash-dot-color, $end-color: transparent, $start-percent: 0, $middle-percent: $dash-dot-width, $end-percent: $dash-dot-width);
|
219
|
+
background-size: $line-width ($dash-dot-width + $dash-space-width);
|
220
|
+
background-repeat: repeat-y;
|
221
|
+
}
|
222
|
+
|
223
|
+
/// 基于渐变实现的水平方向点画线
|
224
|
+
/// @throw 如果要实现的是一个物理像素粗细的线,建议放在一个单独的 DOM 上,方便加上 scale 来实现,否则就不需要顾虑直接用到任意 DOM 上即可,加上 background-position 控制位置,background-color / background-position 等属性必须在该 mixin 的 include 之后开始写。
|
225
|
+
///
|
226
|
+
/// @group 外观
|
227
|
+
/// @name gradient-horizontal-dashed-line
|
228
|
+
/// @param {Number} $dash-dot-width [2px] - 点画线里点的尺寸
|
229
|
+
/// @param {Number} $dash-space-width [2px] - 点画线里点与点间隔尺寸
|
230
|
+
/// @param {Color} $dash-dot-color [$common_color_separator] - 点画线里点的颜色
|
231
|
+
/// @param {Number} $line-width [1px] - 点画线粗细
|
232
|
+
@mixin gradient-horizontal-dashed-line($dash-dot-width: 2px, $dash-space-width: 2px, $dash-dot-color: $common_color_separator, $line-width: 1px) {
|
233
|
+
@include gradient-horizontal-threeColor($start-color: $dash-dot-color, $middle-color: $dash-dot-color, $end-color: transparent, $start-percent: 0, $middle-percent: $dash-dot-width, $end-percent: $dash-dot-width);
|
234
|
+
background-size: ($dash-dot-width + $dash-space-width) $line-width;
|
235
|
+
background-repeat: repeat-x;
|
236
|
+
}
|
@@ -0,0 +1,232 @@
|
|
1
|
+
@charset "utf-8";
|
2
|
+
|
3
|
+
////
|
4
|
+
/// 辅助数值计算的工具方法
|
5
|
+
/// @author Kayo
|
6
|
+
/// @group 数值计算
|
7
|
+
/// @date 2015-08-23
|
8
|
+
////
|
9
|
+
|
10
|
+
/// 获取 CSS 长度值属性(例如:margin,padding,border-width 等)在某个方向的值
|
11
|
+
///
|
12
|
+
/// @name getLengthDirectionValue
|
13
|
+
/// @param {String} $property - 记录着长度值的 SASS 变量
|
14
|
+
/// @param {String} $direction - 需要获取的方向,可选值为 top,right,bottom,left,horizontal,vertical,其中 horizontal 和 vertical 分别需要长度值的左右或上下方向值相等,否则会报 Warning。
|
15
|
+
/// @example
|
16
|
+
/// // UI 界面的一致性往往要求相似外观的组件保持距离、颜色等元素统一,例如:
|
17
|
+
/// // 搜索框和普通输入框分开两种结构处理,但希望搜索框的搜索 icon 距离左边的空白与
|
18
|
+
/// // 普通输入框光标距离左边的空白保持一致,就需要获取普通输入框的 padding-left
|
19
|
+
/// $textField_padding: 4px 5px;
|
20
|
+
/// .dm_textField {
|
21
|
+
/// padding: $textField_padding;
|
22
|
+
/// }
|
23
|
+
/// .dm_searchInput {
|
24
|
+
/// position: relative;
|
25
|
+
/// ...
|
26
|
+
/// }
|
27
|
+
/// .dm_searchInput_icon {
|
28
|
+
/// position: absolute;
|
29
|
+
/// left: getLengthDirectionValue($textField_padding, left);
|
30
|
+
/// ...
|
31
|
+
/// }
|
32
|
+
@function getLengthDirectionValue($property, $direction) {
|
33
|
+
// 声明变量
|
34
|
+
$top: 0;
|
35
|
+
$right: 0;
|
36
|
+
$bottom: 0;
|
37
|
+
$left: 0;
|
38
|
+
// 获取 $property 列表值中值的个数,从而判断是哪种 CSS length 的写法
|
39
|
+
$propertyLength: length($property);
|
40
|
+
@if $propertyLength == 1 {
|
41
|
+
$top: $property;
|
42
|
+
$right: $property;
|
43
|
+
$bottom: $property;
|
44
|
+
$left: $property;
|
45
|
+
} @else if $propertyLength == 2 {
|
46
|
+
$top: nth($property, 1);
|
47
|
+
$right: nth($property, 2);
|
48
|
+
$bottom: nth($property, 1);
|
49
|
+
$left: nth($property, 2);
|
50
|
+
} @else if $propertyLength == 3 {
|
51
|
+
$top: nth($property, 1);
|
52
|
+
$right: nth($property, 2);
|
53
|
+
$bottom: nth($property, 3);
|
54
|
+
$left: nth($property, 2);
|
55
|
+
} @else if $propertyLength == 4 {
|
56
|
+
$top: nth($property, 1);
|
57
|
+
$right: nth($property, 2);
|
58
|
+
$bottom: nth($property, 3);
|
59
|
+
$left: nth($property, 4);
|
60
|
+
} @else {
|
61
|
+
@return 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
// 根据参数中的方向值输出需要的结果
|
65
|
+
@if $direction == top {
|
66
|
+
@return $top;
|
67
|
+
} @else if $direction == right {
|
68
|
+
@return $right;
|
69
|
+
} @else if $direction == bottom {
|
70
|
+
@return $bottom;
|
71
|
+
} @else if $direction == left {
|
72
|
+
@return $left;
|
73
|
+
} @else if $direction == horizontal {
|
74
|
+
@if $left != $right {
|
75
|
+
@warn "左边(#{$left})与右边(#{$right})的值并不相等,不应该直接使用 horizontal 这个方向";
|
76
|
+
}
|
77
|
+
@return $left;
|
78
|
+
} @else if $direction == vertical {
|
79
|
+
@if $top != $bottom {
|
80
|
+
@warn "上边(#{$top})与下边(#{$bottom})的值并不相等,不应该直接使用 vertical 这个方向";
|
81
|
+
}
|
82
|
+
@return $top;
|
83
|
+
} @else {
|
84
|
+
@return 0;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/// 获取两个 CSS 长度值的中间值并取整,通常可用于子元素在父元素中需要居中时计算两者高度差
|
89
|
+
///
|
90
|
+
/// @name getLengthMaxIntegerCenter
|
91
|
+
/// @param {Number | String} $parent - 较大的长度值
|
92
|
+
/// @param {Number | String} $child - 较小的长度值
|
93
|
+
@function getLengthMaxIntegerCenter($parent, $child) {
|
94
|
+
$center: ($parent - $child) / 2;
|
95
|
+
// 注意这里的取整使用 ceil 而不是 floor 并不是随意写的,这是模拟现代浏览器对于小数点长度值的表现而定的。
|
96
|
+
// 例如,margin-top: 10.5px 在现代浏览器中会表现为 margin-top: 11px 而不是 margin-top: 10px
|
97
|
+
// 又例如,margin-top: -10.5px 在现代浏览器的表现等同于 margin-top: -10px 而不是 margin-top: -11px
|
98
|
+
// 即小数长度值会被当成不小于该小数的下一个整数去处理,也就是 ceil 的效果。所以不要随意改成 floor,其他长度值方法也应该如此处理
|
99
|
+
@return ceil($center);
|
100
|
+
}
|
101
|
+
|
102
|
+
/// 获取数值的n次幂的值
|
103
|
+
///
|
104
|
+
/// @name pow
|
105
|
+
/// @param {Number} $number - 底数
|
106
|
+
/// @param {Number} $pow - 幂数
|
107
|
+
/// @example
|
108
|
+
/// pow(10, 5) => 100000
|
109
|
+
/// pow(10, -1) => 0.1
|
110
|
+
@function pow($number, $pow) {
|
111
|
+
$result: 1;
|
112
|
+
@if $pow > 0 {
|
113
|
+
@for $i from 1 through $pow {
|
114
|
+
$result: $result * $number;
|
115
|
+
}
|
116
|
+
} @else if $pow < 0 {
|
117
|
+
@for $i from $pow to 0 {
|
118
|
+
$result: $result / $number;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
@return $result;
|
122
|
+
}
|
123
|
+
|
124
|
+
/// 将数值格式化为指定小数位数的数字。
|
125
|
+
///
|
126
|
+
/// @name toFixed
|
127
|
+
/// @param {Number} $number - 待格式化的数值
|
128
|
+
/// @param {Number} $precision [0] - 精确度(精确到小数点后几位)
|
129
|
+
/// @param {String} $type [round] - 格式化方式("round":"四舍五入","floor":"向下取整","ceil":"向上取整")
|
130
|
+
/// @example
|
131
|
+
/// toFixed(3.1415926535898) => 3.14
|
132
|
+
/// toFixed(3.1415926535898, 4, floor) => 3.1415
|
133
|
+
/// toFixed(3.1415926535898, 4, ceil) => 3.1416
|
134
|
+
/// toFixed(-3.1415926535898, 4, floor) => -3.1416
|
135
|
+
/// toFixed(-3.1415926535898, 4, ceil) => -3.1415
|
136
|
+
/// toFixed(3.1415926535898px) => 3.14px
|
137
|
+
@function toFixed($number, $precision: 0, $type: round) {
|
138
|
+
$result: null;
|
139
|
+
@if $type == round {
|
140
|
+
$result: round($number * pow(10, $precision)) / pow(10, $precision);
|
141
|
+
} @else if $type == floor {
|
142
|
+
$result: floor($number * pow(10, $precision)) / pow(10, $precision);
|
143
|
+
} @else if $type == ceil {
|
144
|
+
$result: ceil($number * pow(10, $precision)) / pow(10, $precision);
|
145
|
+
} @else {
|
146
|
+
@warn "type参数输入有误,请选择输入'round'、'floor'、'ceil'其中一个";
|
147
|
+
$result: $number;
|
148
|
+
}
|
149
|
+
@return $result;
|
150
|
+
}
|
151
|
+
|
152
|
+
/// 阶乘计算
|
153
|
+
///
|
154
|
+
/// @name factorial
|
155
|
+
/// @param {Number} $number - 待进行阶乘计算的数值
|
156
|
+
/// @example
|
157
|
+
/// factorial(4) => 4 * 3 * 2 * 1 => 24
|
158
|
+
@function factorial($number) {
|
159
|
+
$value: 1;
|
160
|
+
@if $number > 0 {
|
161
|
+
@for $i from 1 through $number {
|
162
|
+
$value: $value * $i;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
@return $value;
|
166
|
+
}
|
167
|
+
|
168
|
+
/// 获取 π 的值(11位小数精度)
|
169
|
+
///
|
170
|
+
/// @name pi
|
171
|
+
@function pi() {
|
172
|
+
@return 3.14159265359;
|
173
|
+
}
|
174
|
+
|
175
|
+
/// 通过角度计算弧度
|
176
|
+
///
|
177
|
+
/// @name rad
|
178
|
+
/// @param {Number} $angle - 需要被转换为弧度的角度值
|
179
|
+
/// @example
|
180
|
+
/// rad(180deg) -> 3.14159
|
181
|
+
/// rad(45deg) -> 0.7854
|
182
|
+
@function rad($angle) {
|
183
|
+
$unit: unit($angle);
|
184
|
+
$unitless: $angle / ($angle * 0 + 1);
|
185
|
+
@if $unit == deg {
|
186
|
+
$unitless: $unitless / 180 * pi();
|
187
|
+
}
|
188
|
+
@return $unitless;
|
189
|
+
}
|
190
|
+
|
191
|
+
/// 计算 sin 三角函数
|
192
|
+
///
|
193
|
+
/// @name sin
|
194
|
+
/// @param {Number} $angle - 需要进行 sin 计算的角度值
|
195
|
+
/// @example
|
196
|
+
/// sin(45deg) -> 0.70711
|
197
|
+
/// sin(90deg) -> 1
|
198
|
+
@function sin($angle) {
|
199
|
+
$sin: 0;
|
200
|
+
$angle: rad($angle);
|
201
|
+
@for $i from 0 through 10 {
|
202
|
+
$sin: $sin + pow(-1, $i) * pow($angle, (2 * $i + 1)) / factorial(2 * $i + 1);
|
203
|
+
}
|
204
|
+
@return $sin;
|
205
|
+
}
|
206
|
+
|
207
|
+
/// 计算 cos 三角函数
|
208
|
+
///
|
209
|
+
/// @name cos
|
210
|
+
/// @param {Number} $angle - 需要进行 cos 计算的角度值
|
211
|
+
/// @example
|
212
|
+
/// cos(45deg) -> 0.70711
|
213
|
+
/// cos(90deg) -> 0
|
214
|
+
@function cos($angle) {
|
215
|
+
$cos: 0;
|
216
|
+
$angle: rad($angle);
|
217
|
+
@for $i from 0 through 10 {
|
218
|
+
$cos: $cos + pow(-1, $i) * pow($angle, 2 * $i) / factorial(2 * $i);
|
219
|
+
}
|
220
|
+
@return $cos;
|
221
|
+
}
|
222
|
+
|
223
|
+
/// 计算 tan 三角函数
|
224
|
+
///
|
225
|
+
/// @name tan
|
226
|
+
/// @param {Number} $angle - 需要进行 tan 计算的角度值
|
227
|
+
/// @example
|
228
|
+
/// tan(45deg) -> 1
|
229
|
+
/// tan(50deg) -> 1.19175
|
230
|
+
@function tan($angle) {
|
231
|
+
@return sin($angle) / cos($angle);
|
232
|
+
}
|