我今天遇到了一个问题,我不确定如何有效地处理.正如您在下面的代码中看到的那样,有三个按钮,当单击其中一个按钮时,它们都会移动到指定的位置,然后单击的按钮会改变颜色.
这是我最初希望实现的,然而背景颜色立即改变而不给按钮提供"到达目的地"的机会.我试图通过使用setTimeout()来解决这个问题,但嵌套函数无法识别this
.
$('.groupOfButtons').on('click', function(){
$('#oneButton').animate({
left:"425px",
top:"-=24px"
}, 1000)
$('#anotherButton').animate({
left:"273px",
top:"+=5px"
}, 1000)
$('#oneMoreButton').animate({
left:"137px",
top:"+=34px"
}, 1000)
setTimeout(function(){
$(this).css({'background-color': 'green'})}, 1000) // here!
})
})
Run Code Online (Sandbox Code Playgroud)
如果有人能给我一个很棒的解决方法!但与此同时,我对双嵌套感到好奇this
.如何在一个或多个功能中使用它?可能吗?