我想转换供应商前缀渐变的背景位置,因此我90 - (@degree)
根据这个例子使用了一个简单的公式,它应该是90 - (135) = -45
.
重要的是.replace(/(\d*)?deg/g, 90 - '$1' + 'deg')
,我尝试了不同的函数,但无论如何,输出总是以 NaN 结尾: - parseInt('$1') - parseFloat('$1') - eval(90 - '$1') - Number(' $1')
如果我替换'$1'
为'135'
或任何其他数字,它会很好地工作。
@w3c: true; // valid w3c syntax
@webkit: true; // Google Chrome, Safari, iOS
@moz: true; // Mozilla Firefox
@ms: true; // Internet Explorer
@o: true; // Opera
@default-background-image: linear-gradient(135deg, blue, red), linear-gradient(150deg, green, orange);
.background-image (@arguments: @default-background-image;) {
.result (...) when (@webkit = true) {
background-image: ~`"@{arguments}"
.replace(/[\[\]]/g,'')
.replace("linear-gradient","-webkit-linear-gradient")
.replace(/(\d*)?deg/g, 90 - '$1' + 'deg')`;
}
.result (...) when (@moz = true) {
background-image: ~`"@{arguments}"
.replace(/[\[\]]/g,'')
.replace("linear-gradient","-moz-linear-gradient")
.replace(/(\d*)?deg/g, 90 - '$1' + 'deg')`;
}
.result (...) when (@ms = true) {
background-image: ~`"@{arguments}"
.replace(/[\[\]]/g,'')
.replace("linear-gradient","-ms-linear-gradient")
.replace(/(\d*)?deg/g, 90 - '$1' + 'deg')`;
}
.result (...) when (@o = true) {
background-image: ~`"@{arguments}"
.replace(/[\[\]]/g,'')
.replace("linear-gradient","-o-linear-gradient")
.replace(/(\d*)?deg/g, 90 - '$1' + 'deg')`;
}
.result (...) when (@w3c = true) {
background-image: @arguments;
}
.result (@arguments);
}