【发布时间】:2016-05-08 03:39:08
【问题描述】:
我在玩 Snap,但遇到了一个问题。
我有 this code,我无法在 JSFiddle 上正确设置它,因为我不太习惯它,所以 here's the working version。
我想要实现的是让它在悬停时变宽并在鼠标离开时重置,我正在使用这两个功能来实现:
function shiftBox(box) {
box.animate({
width: parseInt(box.node.getAttribute("width")) + 50,
height: parseInt(box.node.getAttribute("height")) + 50,
x: parseInt(box.node.getAttribute("x")) - 25,
y: parseInt(box.node.getAttribute("y")) - 25
}, 1500, mina.elastic);
}
function resetBox(box) {
box.animate({
width: parseInt(box.node.getAttribute("width")) - 50,
height: parseInt(box.node.getAttribute("height")) - 50,
x: parseInt(box.node.getAttribute("x")) + 25,
y: parseInt(box.node.getAttribute("y")) + 25
}, 1500, mina.elastic);
}
但是,当以高速悬停在其中时,尺寸会永久改变,并且会向左上角移动一点。我猜发生的是一个函数在另一个函数有时间完全更改值之前被调用。 是否有一个 JS 函数可以让一个函数等到另一个函数完成,或者我应该存储我需要预先重置它的值?
【问题讨论】:
标签: javascript html svg snap.svg