JQuery: increment not working. (Newby Stuff) (1 Viewer)

BlueIshDan

☠
Local time
Today, 17:06
Joined
May 15, 2014
Messages
1,122
So tea instead of coffee this morning was a mistake!

I am sad to admit that a simple incrementation has me stumped. Haha!

Does anyone understand why my increment is not working correctly.

My attempt was to make the two adds locations traverse through the adds array.

The adds_bottom seems to display only 0 and 2 and the adds_right displays only 1.

PHP:
    var urls = [
            "http://admin.csrwire.com/system/profile_logos/12774/original/wmt_logo_2.JPG",
            "http://myfrugaladventures.com/wp-content/uploads/2010/07/target_logo.gif",
            "https://cantire.taleo.net/careersection/theme/101/1334777976000/en/theme/images/CT_HorzW_Std_RGB.PNG"];
    
    var index = 0;
    
    $("#adds_bottom img:first").attr("src", urls[index++]);
    $("#adds_right img:first").attr("src", urls[index++]);
    window.setInterval(RotateAdds, 5000);

    function RotateAdds()
    {
        
        $("#adds_bottom img:first").hide("fast",
                function ()
                {
                    $("#adds_bottom img:first").attr("src", urls[index++]);
                });

        $("#adds_bottom img:first").show("fast");
        
        if (index === urls.length) index = 0;

        $("#adds_right img:first").hide("fast",
                function ()
                {
                    $("#adds_right img:first").attr("src", urls[index++]);
                });

        $("#adds_right img:first").show("fast");

        if (index === urls.length) index = 0;
    }
 

BlueIshDan

☠
Local time
Today, 17:06
Joined
May 15, 2014
Messages
1,122
Guess I got it with this...

PHP:
    var adds = ["#adds_right img:first", "#adds_bottom img:first"]
    var urls = [
            "http://admin.csrwire.com/system/profile_logos/12774/original/wmt_logo_2.JPG",
            "http://myfrugaladventures.com/wp-content/uploads/2010/07/target_logo.gif",
            "https://cantire.taleo.net/careersection/theme/101/1334777976000/en/theme/images/CT_HorzW_Std_RGB.PNG"];

    var urls_index = 0;

    $("#adds_bottom img:first").attr("src", urls[urls_index++]);
    $("#adds_right img:first").attr("src", urls[urls_index++]);

    window.setInterval(RotateAdds, 5000);

    function RotateAdds()
    {
        adds.every(function (element, index, array)
        {
            $(element).hide("fast",
                    function ()
                    {
                        $(element).attr("src", urls[urls_index++]);
                        if (urls_index >= urls.length) urls_index = 0;
                    });

            $(element).show("fast");
            return true;
        });
    }

Thanks
 

Users who are viewing this thread

Top Bottom