我想创建一个背景图像。具有以下功能的梯度混合:
- 无限量(尚未完成,但有点工作)
- 调整供应商前缀(部分有效)
我尝试了lesshat,但遗憾的是它不符合这些要求,因为它没有正确调整渐变方向。所以我最终使用了一堆 .replace 东西,这些东西并不完美,而且还没有适应程度值。
我无法弄清楚度数背后的数学原理,因为值不同,而 45deg (w3c) 保持 45deg (vendor),135deg (w3c) 是 -45deg (vendor)。
有没有更好的解决方案?
// Vendor Prefixes
// ==========================================================================
@w3c: true; // valid w3c syntax
@webkit: true; // Google Chrome, Safari, iOS
@opera: true; // Opera
@moz: true; // Mozilla Firefox
@ms: true; // Internet Explorer
.background-image (...) {
.result (@arguments, @vendor) when (@vendor = true) {
background-image: @arguments;
}
@background-image-webkit: ~`'@{arguments}'.replace('linear-gradient','-webkit-linear-gradient').replace('to top right','45deg').replace('to top left','135deg').replace('to bottom right','-45deg').replace('to bottom left','-135deg').replace('to top','bottom').replace('to right','left').replace('to bottom','top').replace('to left','right')`;
@background-image-moz: ~`'@{arguments}'.replace('linear-gradient','-moz-linear-gradient').replace('to top right','45deg').replace('to top left','135deg').replace('to bottom right','-45deg').replace('to bottom left','-135deg').replace('to top','bottom').replace('to right','left').replace('to bottom','top').replace('to left','right')`;
@background-image-ms: ~`'@{arguments}'.replace('linear-gradient','-ms-linear-gradient').replace('to top right','45deg').replace('to top left','135deg').replace('to bottom right','-45deg').replace('to bottom left','-135deg').replace('to top','bottom').replace('to right','left').replace('to bottom','top').replace('to left','right')`;
@background-image-opera: ~`'@{arguments}'.replace('linear-gradient','-o-linear-gradient').replace('to top right','45deg').replace('to top left','135deg').replace('to bottom right','-45deg').replace('to bottom left','-135deg').replace('to top','bottom').replace('to right','left').replace('to bottom','top').replace('to left','right')`;
@background-image-w3c: @arguments;
.result (@background-image-webkit, @webkit);
.result (@background-image-moz, @moz);
.result (@background-image-ms, @ms);
.result (@background-image-opera, @opera);
.result (@background-image-w3c, @w3c);
}
@type: linear-gradient;
@dir: ~'to bottom';
@start: steelblue;
@stop: crimson;
@type2: linear-gradient;
@dir2: ~'to bottom';
@start2: blue;
@stop2: red;
single {
.background-image (~`'@{type}(@{dir},@{start},@{stop})'`);
}
multiple {
.background-image (~`'@{type}(@{dir},@{start},@{stop}),@{type2}(@{dir2},@{start2},@{stop2})'`);
}
/* Linear
.replace('to top right','45deg').replace('to top left','135deg').replace('to bottom right','-45deg').replace('to bottom left','-135deg').replace('to top','bottom').replace('to right','left').replace('to bottom','top').replace('to left','right')
*/
/* Radial
.replace('radial-gradient','-webkit-radial-gradient').replace('ellipse at center','center, ellipse cover')
*/