簡體   English   中英

jQuery動畫回調不起作用

[英]jQuery animation callback doesn't work

為什么不發出警報?

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');
});

您可以使用多種不同的語法選項.animate() 當你傳遞一個屬性對象和一個options對象(就像你正在做的那樣)時,completion函數會在options對象中進入,而不是像這樣的第三個參數:

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).

嘗試將第三個參數指定為“完整”,如下所示:

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');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM