【问题标题】:jQuery cycle.all.js first slide timeoutjQuery cycle.all.js 第一张幻灯片超时
【发布时间】:2013-05-18 21:23:05
【问题描述】:

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

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

【问题讨论】:

  • 只是一个关于你的 CS 的注释。 @ 映射到 this

标签: jquery coffeescript


【解决方案1】:

您可以使用delay 选项来执行此操作,并给它一个负值:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 2013-08-24
    • 2021-01-17
    • 2013-04-29
    • 1970-01-01
    相关资源
    最近更新 更多