Обратный вызов анимации jQuery не работает - PullRequest
4 голосов
/ 13 декабря 2011

Почему не срабатывает предупреждение?

var $anchor = $(this);

$('.hide').val($(this).attr('href'));
$('html, body').animate({
    scrollLeft: $($anchor.attr('href')).offset().left
}, {
    queue: false,
    duration: 1000,
    easing: 'easeInOutCirc'
}, function () {
    alert('test');
});

Ответы [ 2 ]

9 голосов
/ 13 декабря 2011

Есть несколько различных синтаксических опций, которые вы можете использовать с .animate(). Когда вы передаете объект свойств и объект параметров (как вы это делаете), функция завершения переходит в объект параметров не как третий параметр, подобный следующему:

var $anchor = $(this);

$('.hide').val($(this).attr('href'));
$('html, body').animate({
    scrollLeft: $($anchor.attr('href')).offset().left
  }, {
    queue: false,
    duration: 1000,
    easing: 'easeInOutCirc',
    complete: function () {
        alert('test');
    }
  }
);

Это полностью описано в jQuery .animate () doc .

.animate( properties, options )

properties - A map of CSS properties that the animation will move toward.

options - A map of additional options to pass to the method. Supported keys:
    duration: A string or number determining how long the animation will run.
    easing: A string indicating which easing function to use for the transition.
    complete: A function to call once the animation is complete.
    step: A function to be called after each step of the animation.
    queue: A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string.
    specialEasing: A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions (added 1.4).
2 голосов
/ 13 декабря 2011

попробуйте указать третий параметр как «полный», например:

var $anchor = $(this);

$('.hide').val($(this).attr('href'));
$('html, body').animate({
    scrollLeft: $($anchor.attr('href')).offset().left
}, {
    queue: false,
    duration: 1000,
    easing: 'easeInOutCirc'
}, complete: function () {
    alert('test');
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...