jQuery动画返回回调值

时间:2012-12-23 19:22:22

标签: jquery jquery-animate jquery-callback

我很确定这个问题的答案在某个地方浮动,但我不知道要搜索哪些关键字......

得到了这个:

...
var currLeft = $(window).scrollLeft();
$('html, body').animate({
    scrollLeft: currLeft+width+'px'
}, 1200, function(){
    currLeft = $(window).scrollLeft();
});
...

动画完成后,我想用'first'currLeft ...替换function()中的currLeft ...

更新 感谢所有的答案,但你指出的方向并不是我想要的:-) 假设你有这个:

var currLeft = 'Whats your name?';
$('html, body').animate({
    scrollLeft: currLeft+width+'px'
}, 1200, function(){
    currLeft = 'Its Hank'
});

我想取代'你的名字是什么?'在这种情况下,“它的汉克”,第一个currLeft仍然是:'你的名字是什么?'

2 个答案:

答案 0 :(得分:0)

我不确定但可能是这样:

var currLeft = $(window).scrollLeft();
$('html, body').animate({
    scrollLeft: currLeft+width+'px'
}, 1200, function(){
    $('html, body').scrollLeft(currLeft);
});

答案 1 :(得分:0)

试试这个:

var currLeft = $(window).scrollLeft(),
    currLeft2 = "";
$('html, body').animate({
  scrollLeft: currLeft+width+'px'
}, 1200, function(){
  currLeft2 = 'Its hank';
});