What you need is a @mixin which does take parameters. Given the structure of your image URLs, I think you need two arguments, one for the image name and one for its extension:
@mixin bgImageFunction($imageName, $imageExt) {
$path: '/img/' + $imageName;
background-image: url("#{$path}-medium.#{$imageExt}");
@media (max-width: 640px) {
background-image: url("#{$path}-low.#{$imageExt}");
}
@media (min-width: 1600px) {
background-image: url("#{$path}-high.#{$imageExt}");
}
}
div {
background-size: 100%;
@include bgImageFunction('img1', 'png');
}
You can also use a default parameter for the extension and only pass the name as argument:
@mixin bgImageFunction($imageName, $imageExt: 'png') {
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…