jquery 动画函数在多线程上工作吗?
在我的代码中......假设我点击顶部按钮并调用函数工作正常......
现在单击任何剩余的一次....第二个功能也可以使用,但也可以使用第一个调用。
那么,我如何一次调用一个函数?
它是多线程吗?这是杀死它的方法吗?
<table width="1200px" height="600px" align="center">
<tr>
<td>
</td>
<td style="text-align: center">
<button id="btntop">
top</button>
</td>
<td>
</td>
</tr>
<tr>
<td style="text-align: right">
<button id="btnleft">
left</button>
</td>
<td style="text-align: center">
<img id="book" src="Image/images.jpg" alt="" width="250" height="123" style="position: relative;
left: 10px;" />
</td>
<td>
<button id="btnright">
right</button>
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: center">
<button id="btnbottom">
bottom</button>
</td>
<td>
</td>
</tr>
</table>
<script type="text/javascript">
function anim(direction) {
if (direction == "top") {
$('#book').animate({
top: '-=10'
}, 200, function () {
anim("top");
});
}
if (direction == "left") {
$('#book').animate({
left: '-=10'
}, 200, function () {
anim("left");
});
}
if (direction == "right") {
$('#book').animate({
left: '+=10'
}, 200, function () {
anim("right");
});
}
if (direction == "bottom") {
$('#book').animate({
top: '+=10'
}, 200, function () {
anim("bottom");
});
}
}
$('#btntop').hover(function () {
anim("top");
});
$('#btnleft').hover(function () {
anim("left");
});
$('#btnright').hover(function () {
anim("right");
});
$('#btnbottom').hover(function () {
anim("bottom");
});
</script>