0

I am creating a slider using prototype javascrtipt

My problem is when slider goes to 5 th slide it again slides back to 1 st slide in sequence(5,4,3,2,1) and it is starting from 1 slide

Can any one explain how should i over come this thank you very much..

var slider;
Event.observe(window, 'load', function() {
    slider = new MOSS('moss_panel', '', 'moss_panel', null, 1, true, false, 1);
    m_TimeOutSlider = setTimeout("MOSSSlideShow('1')", 1000);
});


function MOSSSlideShow() {

    clearTimeout(m_TimeOutSlider);
    slider.next();
    if (slider.offset == 5) {
        slider.offset = -1;
    }
    m_TimeOutSlider = setTimeout("MOSSSlideShow()",5000);
}

this is my code in javascript

Rob W
  • 341,306
  • 83
  • 791
  • 678
srikumar
  • 1
  • 1
  • "Can any one explain how should i over come this thank you very much.." what effect do you want? do you want the sliding to stop after the 5th one? You are recursively initiating timer for the slideshow again with `m_TimeOutSlider = setTimeout("MOSSSlideShow()",5000);` inside the function `MOSSSlideShow()` so it is never stopping – Sandeepan Nath Dec 14 '10 at 16:01
  • Yeah i want to stop the slide show at 5 th slide and start it again from 1 st slide sta....As of now its rolling back in a sequence (5,4,3,2,1).And it starts from 1st slide... – srikumar Dec 14 '10 at 16:04
  • What parameters are needed to for the `Moss()` class? You are passing many params. I have not worked with this Moss slider, but if you tell a little more I can help – Sandeepan Nath Dec 14 '10 at 16:15

2 Answers2

0

This simple javascript timer code will give you some idea and your logic can be derived from that -

Code for a simple JavaScript countdown timer?

Community
  • 1
  • 1
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
0

Instead of messing about with timers and intervals, and since you have Prototype, use the PeriodicalExecuter.

document.observe('dom:loaded', function() {
    var slider = new MOSS('moss_panel', '', 'moss_panel', null, 1, true, false, 1);
    new PeriodicalExecuter(slider.next, 5);
});

(This is a simplistic example, it doesn't rotate from "5" to "1", it would be neatest if you wrote that into slider.next())

clockworkgeek
  • 37,650
  • 9
  • 89
  • 127