jQuery cycle.all.js第一次幻灯片超时



我使用的是cycle.all.js jQuery插件(http://jquery.malsup.com/cycle/)。现在它工作得很好,但我需要第一个图像的超时时间比所有其他的都短。因此,当用户第一次将鼠标悬停在slideshow-div上时,循环立即开始,但在第一张幻灯片之后,它将超时更改为650。这是我的代码现在的样子:

$('div#slideshow').mouseenter(->
  $(this).cycle
    fx: "fade",
    speed: 1
    timeout: 650
  ).mouseleave ->
    $(this).cycle 'stop'

您可以使用delay选项并给它一个负值:

$(this).cycle
    fx: "fade",
    speed: 1
    timeout: 650
    delay: -650
)

注意,这会导致它立即转到第二张幻灯片,我认为这是您想要的,因为在用户将鼠标悬停在幻灯片上之前,幻灯片的第一张图像已经可见。

正如Benjamin指出的,在Coffeescript中,您可以使用@作为this的快捷方式:

$('div#slideshow').mouseenter(->
  $(@).cycle
    fx: "fade",
    speed: 1,
    timeout: 650,
    delay: -650  //go to the next slide immediately
  ).mouseleave ->
    $(@).cycle 'stop'

最新更新