0

this is my javascript code only work on click event and i want to make this auto slideshow. please help me i have no knowledge how to do it..

var wflSliders = ({});
var wflSlider = new Class({
    Implements:[Options,Events],
    initialize:function(options){
        this.setOptions(options);
        if(this.options.ribbon_behavior == 'scroll'){
            this.wrapper = $('rand_products_wfl_'+this.options.id);
            if(this.wrapper){
            this.ribbon = this.wrapper.getElement('.jspw_ribbon');
            this.scroll_r = this.wrapper.getElement('.jspw_scroll');
            this.lt = this.wrapper.getElement('.jspw_ribon_button_lt');
            this.rb = this.wrapper.getElement('.jspw_ribon_button_rb');
            this.blocks = this.wrapper.getElements('.jspw_prod');
            var blockSize = this.blocks[0].getComputedSize();
            var dim = (this.options.orientation == 'hor')?'x':'y';
            if(this.options.effect_block == 'single'){
                this.offset=(dim=='x')?blockSize.totalWidth:blockSize.totalHeight;
            }

2 Answers2

1

One way to approach is that you can use a built-in function called setInterval in Javascript and after wrapping your code in a function call it in the interval you desire to have your slideshow speed.

Like the following:

setInterval(function(){
   slideShow(); // Every second the function is called
},1000);

Check the documentation here for more understanding: MDN Documentation for setInterval function

UPDATE: Givi just proved to me (in the comments of my answer) that my answer was not right. It has high risk that you use my suggested approach and better to use setTimeout recursively like this:

function slideShow() {
    setTimeout(function() {
       slideShow();
    }, 1000);
}
ambodi
  • 6,116
  • 2
  • 32
  • 22
  • Very bad idea to use setInterval with DOM manipulation. Instead, would be better to use recursive setTimeout. – Givi Dec 03 '13 at 16:26
  • I am open to new ideas, but actually I think they are the same. Read up here: http://stackoverflow.com/questions/2696692/setinterval-vs-settimeout. It is just the matter of executing once or several times. I know that some people think it is a bad idea to use it (http://zetafleet.com/blog/why-i-consider-setinterval-harmful) but that is not a rule of thumb! – ambodi Dec 03 '13 at 20:09
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/Window.setInterval#Dangerous_usage – Givi Dec 03 '13 at 20:13
-1

you can us slide show plugin. Good luck

dinhmv
  • 1