Cristian Cristian - 25 days ago 12
Javascript Question

javascript repeat event function

I try use this combination of function and repeat with setinterval , and add one unit in each time as i use in this script i create :

<script>
function rot(num) {
var hide = num - 1;
jQuery("#ss" + hide).hide(1000);
jQuery("#ss" + num).show(1000);
var_end = num + 1;
}
var ini = 1;
setInterval(function () {
if (end == "") {
rot(ini);
} else {
rot(end);
}
}, 5000);
</script>

<div id="ss1" style="display:none;">yy</div>
<div id="ss2" style="display:none;">yy</div>


Each 5 seconds repeat and sen the number 1 for open div with number 1 and after this detect new number add 1 and hide until div and show the div with number 2 , i try many times but i don´t know why don´t want works , howewer don´t send value to function i don´t know

Answer

Maybe you forget to declare variables

<script>
    var end = "";
    var ini = 1;
    function rot(num)
    {
        var hide= num - 1;
        jQuery("#ss"+hide).hide(1000);
        jQuery("#ss"+num).show(1000);
        end = num + 1;
    }

    setInterval(function(){ 
        if (end == "") {
            rot(ini);
        } else {
            rot(end);
        }
    },5000);
</script>