When it comes to CSS keyframe animations, there are essentially two parts involved: the animation name specified in the style and the @keyframes declaration in the root section. In order to create a mixin as you have described, the setup would need to look something like this:
@mixin bgAnimation($name, $start-position, $end-position) {
animation-name: $name;
@at-root {
@keyframes #{$name} {
0% {
background-position: $start-position;
}
100% {
background-position: $end-position;
}
}
}
}
To apply the mixin, you can do the following:
.class {
animation: 10s linear;
animation-iteration-count: infinite;
@include bgAnimation(animation-name, 0px, 100px);
}
After compilation, the resulting CSS would be:
.class {
animation: 10s linear;
animation-iteration-count: infinite;
animation-name: animation-name;
}
@keyframes animation-name {
0% {
background-position: 0px;
}
100% {
background-position: 100px;
}
}