Где поместить этот блок сценария, чтобы это слайд-шоу могло двигаться автоматически? - PullRequest
0 голосов
/ 28 января 2011

Я задал вопрос о том, как сделать так, чтобы слайд-шоу jQuery Blinds автоматически перемещалось, и кто-то ответил на этой странице (тот, у кого 12 голосов):способ сделать это слайд-шоу автоматически?

Кажется, код работает для большинства людей, но я не могу заставить его работать на меня.Я использовал оригинальный демонстрационный файл и разместил код в самом низу jquery.blinds-0.9.js, сразу после "}) (jQuery);"но слайд-шоу все еще не движется.Что я делаю неправильно?Я проверил имена классов, и они верны.

Это тот блок скрипта:

var SlideChanger = function(seconds_each) {
  var index = -1; 
  // on the first cycle, index will be set to zero below
  var maxindex = ($(".change_link").length) - 1; 
  // how many total slides are there (count the slide buttons)
  var timer = function() { 
  // this is the function returned by SlideChanger
    var logic = function() { 
    // this is an inner function which uses the 
    // enclosed values (index and maxindex) to cycle through the slides
      if (index == maxindex) 
        index = 0; // reset to first slide
      else
        index++; // goto next slide, set index to zero on first cycle
      $('.slideshow').blinds_change(index); // this is what changes the slide
      setTimeout(logic, 1000 * seconds_each); 
      // schedule ourself to run in the future
    }
    logic(); // get the ball rolling
  }
  return timer; // give caller the function
}

SlideChanger(5)(); // get the function at five seconds per slide and run it

1 Ответ

0 голосов
/ 28 января 2011

Попробуйте заключить последнюю строку SlideChanger(5)(); в document.ready, например:

$(function(){SlideChanger(5)();})

В противном случае $(".change_link").length вернет 0

...