The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
4 posters

    What's wrong with this JavaScript?

    VelvetMoon
    VelvetMoon
    Forumember


    Posts : 33
    Reputation : 1
    Language : English

    Solved What's wrong with this JavaScript?

    Post by VelvetMoon January 20th 2012, 12:13 am

    Hello,

    Was sorting out my random banner scroll, added this new Javascript, but it won't work with the scroll every 3 seconds.

    Code:

    });

            $(function() {
            var a = ["http://i42.tinypic.com/2ujqqyv.png", "http://img685.imageshack.us/img685/8762/32835484.png", "http://img850.imageshack.us/img850/1261/72655719.jpg", "http://img839.imageshack.us/img839/1759/40100640.jpg",  "http://img221.imageshack.us/img221/2205/32895956.png", "http://img85.imageshack.us/img85/9394/12988506.png", "http://i42.tinypic.com/2ujqqyv.png"],
            b=function(){$("#pun-logo img,#i_logo,#logo img").attr("src",a[Math.floor(Math.random()*a.length)])};b();setInterval(b,3*1000);
            });

    And is there any way to make the banners scroll in a order?
    Additional info: http://www.animecookies.nstars.org - PhPBB3

    Thanks.


    Last edited by VelvetMoon on January 21st 2012, 9:19 pm; edited 2 times in total
    avatar
    Guest
    Guest


    Solved Re: What's wrong with this JavaScript?

    Post by Guest January 20th 2012, 6:34 am

    Try replace that with:
    Code:
     $(function() {
            var a = ["http://i42.tinypic.com/2ujqqyv.png",
    "http://img685.imageshack.us/img685/8762/32835484.png",
    "http://img850.imageshack.us/img850/1261/72655719.jpg",
    "http://img839.imageshack.us/img839/1759/40100640.jpg", 
    "http://img221.imageshack.us/img221/2205/32895956.png",
    "http://img85.imageshack.us/img85/9394/12988506.png",
    "http://i42.tinypic.com/2ujqqyv.png"];
            b=function(){$("#pun-logo img,#i_logo,#logo img").attr("src",a[Math.floor(Math.random()*a.length)])};b();setInterval(b,3*1000);
            });
    LGforum
    LGforum
    Hyperactive


    Male Posts : 2265
    Reputation : 264
    Language : English
    Location : UK

    Solved Re: What's wrong with this JavaScript?

    Post by LGforum January 20th 2012, 10:24 am

    If your not wanting it to be in a random order, and instead cycle through a set of images, then its a very easy piece of Javascript to write.

    Judging by the script your using, your using punbb, and want the logo to cycle through those images every three second.
    So i'll brb in a few mins and edit this post with a much better script.
    FL.ux
    FL.ux
    Forumember


    Male Posts : 841
    Reputation : 18
    Language : I hope I could be a FM staff :'(
    Location : I shall fly to the subterranean sky.

    Solved Re: What's wrong with this JavaScript?

    Post by FL.ux January 20th 2012, 10:29 am

    LGforum wrote:If your not wanting it to be in a random order, and instead cycle through a set of images, then its a very easy piece of Javascript to write.

    Judging by the script your using, your using punbb, and want the logo to cycle through those images every three second.
    So i'll brb in a few mins and edit this post with a much better script.

    she;s using phpbb2 Razz
    LGforum
    LGforum
    Hyperactive


    Male Posts : 2265
    Reputation : 264
    Language : English
    Location : UK

    Solved Re: What's wrong with this JavaScript?

    Post by LGforum January 20th 2012, 10:31 am

    Then that will be why her script isn't working Razz Since its for punbb.
    FL.ux
    FL.ux
    Forumember


    Male Posts : 841
    Reputation : 18
    Language : I hope I could be a FM staff :'(
    Location : I shall fly to the subterranean sky.

    Solved Re: What's wrong with this JavaScript?

    Post by FL.ux January 20th 2012, 10:35 am

    LGforum wrote:Then that will be why her script isn't working Razz Since its for punbb.


    you should give her code for phpbb2. . . 'cause i'm sure that's what she's lookin' for Laughing
    LGforum
    LGforum
    Hyperactive


    Male Posts : 2265
    Reputation : 264
    Language : English
    Location : UK

    Solved Re: What's wrong with this JavaScript?

    Post by LGforum January 20th 2012, 10:55 am

    Something like this would work for all board:

    Code:

    var images=[];
    images[0]="http://i42.tinypic.com/2ujqqyv.png";
    images[1]="http://img685.imageshack.us/img685/8762/32835484.png";
    images[2]="http://img850.imageshack.us/img850/1261/72655719.jpg";
    images[3]="http://img839.imageshack.us/img839/1759/40100640.jpg";
    images[4]="http://img221.imageshack.us/img221/2205/32895956.png";
    images[5]="http://img85.imageshack.us/img85/9394/12988506.png";
    images[6]="http://i42.tinypic.com/2ujqqyv.png";

    var curnum=0;
    function slideShow() {
    var elem=document.getElementById('pun-logo').firstChild;
    elem.src=images[curnum];
    curnum=curnum+1;
    if (curnum==images.length){ curnum=0 }
    setTimeout("slideShow();",3000);
    }

    All that needs changing is the value of 'elem' for each board. And the function will need called on to start it off.
    VelvetMoon
    VelvetMoon
    Forumember


    Posts : 33
    Reputation : 1
    Language : English

    Solved Re: What's wrong with this JavaScript?

    Post by VelvetMoon January 20th 2012, 1:39 pm

    Thanks, I've entered the code in, but what do I need to do with 'elem' exactly?
    VelvetMoon
    VelvetMoon
    Forumember


    Posts : 33
    Reputation : 1
    Language : English

    Solved Re: What's wrong with this JavaScript?

    Post by VelvetMoon January 20th 2012, 10:20 pm

    Oh, and forgot to ask! Does it work with Phpbb3? D:
    LGforum
    LGforum
    Hyperactive


    Male Posts : 2265
    Reputation : 264
    Language : English
    Location : UK

    Solved Re: What's wrong with this JavaScript?

    Post by LGforum January 20th 2012, 10:36 pm

    'elem' will simply need changing to match the img element of the main forum logo. It can be used for all boards.

    This bit goes into Javascript Management:
    Code:

           
            var images=[];
            images[0]="http://i42.tinypic.com/2ujqqyv.png";
            images[1]="http://img685.imageshack.us/img685/8762/32835484.png";
            images[2]="http://img850.imageshack.us/img850/1261/72655719.jpg";
            images[3]="http://img839.imageshack.us/img839/1759/40100640.jpg";
            images[4]="http://img221.imageshack.us/img221/2205/32895956.png";
            images[5]="http://img85.imageshack.us/img85/9394/12988506.png";
            images[6]="http://i42.tinypic.com/2ujqqyv.png";
           
            var curnum=0;
            function slideShow() {
            var elem=document.getElementById('pun-logo').firstChild;
            elem.src=images[curnum];
            curnum=curnum+1;
            if (curnum==images.length){ curnum=0 }
            setTimeout("slideShow();",3000);
            }
    Its obvious where to add your image URLs.

    For punBB leave it as it is.
    For phpbb3:

    swap this line:
    Code:

    var elem=document.getElementById('pun-logo').firstChild;

    For this:
    Code:

    var elem=document.getElementById('logo').firstChild;

    The script will need to be started by calling the function.
    You can do that by putting this:
    Code:
    <script>slideShow();</script>
    Into an announcement, or widget.
    Nera.
    Nera.
    Energetic


    Female Posts : 7078
    Reputation : 2017
    Language : English
    Location : -

    Solved Re: What's wrong with this JavaScript?

    Post by Nera. January 20th 2012, 10:48 pm

    VelvetMoon wrote:Thanks, I've entered the code in, but what do I need to do with 'elem' exactly?
    VelvetMoon wrote:Oh, and forgot to ask! Does it work with Phpbb3? D:
    Please don't double post. Your post need to be separated by 24 hours before bumping, replying or adding more information. Please use the edit button instead, thank you Wink
    VelvetMoon
    VelvetMoon
    Forumember


    Posts : 33
    Reputation : 1
    Language : English

    Solved Re: What's wrong with this JavaScript?

    Post by VelvetMoon January 20th 2012, 11:16 pm

    Sorry. -.-

    And my current code is now:

    Code:
    var images=[];
            images[0]="http://i42.tinypic.com/2ujqqyv.png";
            images[1]="http://img717.imageshack.us/img717/3789/37295971.png";
            images[2]="http://img850.imageshack.us/img850/1261/72655719.png";
            images[3]="http://img839.imageshack.us/img839/1759/40100640.png";
            images[4]="http://img221.imageshack.us/img221/2205/32895956.png";
            images[5]="http://img85.imageshack.us/img85/9394/12988506.png";
            images[6]="http://i42.tinypic.com/2ujqqyv.png";
            images[7]="http://img69.imageshack.us/img69/3917/58039496.png";
            images[8]="http://i42.tinypic.com/2ujqqyv.png";
            images[9]="http://img854.imageshack.us/img854/8174/89132615.png";
            images[10]="http://img18.imageshack.us/img18/3915/70701673.png"
         

            var curnum=0;
            function slideShow() {
            var png=document.getElementById('logo').firstChild;
            png.src=images[curnum];
            curnum=curnum+1;
            if (curnum==images.length){ curnum=0 }
            setTimeout("slideShow();",3000);
            }

    <script>slideShow();</script>

    But the pause between waiting for a new banner to scroll on the page is annoying (i.e one banner comes on, goes off, ten seconds later another one comes on, etc).
    And it is only showing the first three banners. Have I missed something?

    Is there any way I can stop the gap between the loading banners? And what about the banners?

    LGforum
    LGforum
    Hyperactive


    Male Posts : 2265
    Reputation : 264
    Language : English
    Location : UK

    Solved Re: What's wrong with this JavaScript?

    Post by LGforum January 21st 2012, 2:24 am

    The pause is due to the page having to load a new image each time.
    If you don't want that, then the images will have to be loaded on your page somewhere, which will slow down the overall loading of the forum due to having to load so many big images on page load.
    VelvetMoon
    VelvetMoon
    Forumember


    Posts : 33
    Reputation : 1
    Language : English

    Solved Re: What's wrong with this JavaScript?

    Post by VelvetMoon January 21st 2012, 11:16 am

    Thanks.

    Sorted.
    Nera.
    Nera.
    Energetic


    Female Posts : 7078
    Reputation : 2017
    Language : English
    Location : -

    Solved Re: What's wrong with this JavaScript?

    Post by Nera. January 21st 2012, 10:01 pm

    Topic Solved & Locked

      Current date/time is November 11th 2024, 7:30 pm