代码之家  ›  专栏  ›  技术社区  ›  Aistina

在jQuery中创建幻灯片(不是图像)

  •  0
  • Aistina  · 技术社区  · 16 年前

    div 包含在一个容器中的元素 div

    我的HTML如下所示:

    <div id="topMaps" style="height: 225px; overflow: hidden;">
      <div>First slide - some content here</div>
      <div>Second slide - some content here</div>
      <div>... slide - some content here</div>
      <div>n'th slide - some content here</div>
    </div>
    

    我正在为此使用以下脚本:

    var currentSlide = 1;
    var numSlides = -1;
    var slideSpeed = 1000;
    var timePerSlide = 3500;
    
    function nextSlide() {
        $('#topMaps div:nth-child(' + currentSlide + ')').hide("slide", { direction: "left" }, slideSpeed);
        currentSlide += 1;
        if (currentSlide >= numSlides)
            currentSlide = 1;
        $('#topMaps div:nth-child(' + currentSlide + ')').show("slide", { direction: "left" }, slideSpeed);
    
        setTimeout(nextSlide, timePerSlide);
    }
    
    $(document).ready(function() {
        numSlides = $('#topMaps div').length;
        setTimeout(nextSlide, timePerSlide);
    });
    

    但它不起作用。当 nextSlide

    o.easing[this.options.easing || (o.easing.swing ? "swing" : "linear")] is not a function
    http://localhost/templates/front/default/js/jquery.js
    Line 19
    

    当我加上 $('#topMaps div:nth-child(' + currentSlide + ')')

    $('#topMaps>div:nth-child(' + currentSlide + ')') (请注意 > ).但还是不行。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Yacoby    16 年前

    虽然不是您想要的答案,但您是否考虑过使用 Cycle Plugin ?

        2
  •  0
  •   Khodor    16 年前