【发布时间】:2018-10-03 09:39:48
【问题描述】:
我已经为一些按钮设置了样式,并希望使用 Anime.js 在 Vue 组件中为它们设置动画。
<div class="links">
<a
class="button green"
href="#"
target="_blank"
@mouseover="bouncyButtonEnter"
@mouseout="bouncyButtonLeave">
<svg viewBox="0 0 180 60">
<path ref="buttonPath" d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"/>
</svg>
<span ref="buttonSpan">CodePen</span>
</a>
<a
class="button blue"
href="#"
target="_blank"
@mouseover="bouncyButtonEnter"
@mouseout="bouncyButtonLeave">
<svg viewBox="0 0 180 60">
<path ref="buttonPath" d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"/>
</svg>
<span ref="buttonSpan">Github</span>
</a>
<a
class="button red"
href="#"
target="_blank"
@mouseover="bouncyButtonEnter"
@mouseout="bouncyButtonLeave">
<svg viewBox="0 0 180 60">
<path ref="buttonPath" d="M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z"/>
</svg>
<span ref="buttonSpan">Contact</span>
</a>
</div>
<script>
import anime from "animejs";
export default {
data() {
return {};
},
methods: {
bouncyButtonEnter: function() {
anime.remove([this.$refs.buttonPath, this.$refs.buttonSpan]);
anime({
targets: this.$refs.buttonPath,
d:
"M10,10 C10,10 50,7 90,7 C130,7 170,10 170,10 C170,10 172,20 172,30 C172,40 170,50 170,50 C170,50 130,53 90,53 C50,53 10,50 10,50 C10,50 8,40 8,30 C8,20 10,10 10,10 Z",
elasticity: 700,
offset: 0
});
anime({
targets: this.$refs.buttonSpan,
scale: 1.15,
duration: 800,
offset: 0
});
},
bouncyButtonLeave: function() {
anime.remove([this.$refs.buttonPath, this.$refs.buttonSpan]);
anime({
targets: this.$refs.buttonPath,
d:
"M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z",
elasticity: 700,
offset: 0
});
anime({
targets: this.$refs.buttonSpan,
scale: 1,
duration: 800,
offset: 0
});
}
}
};
</script>
我正在尝试使用 Refs 的方法 bouncyButtonEnter 和 bouncyButtonLeave 来制作动画,并且它应该工作。我的问题是它只适用于一个按钮。我应该如何使它工作,以便每个按钮都会动画?
我在Sandbox也有一个代码
【问题讨论】:
标签: vue.js vue-component anime.js