MyBB Source


Enter the Guess MyBB 1.6 Release Date Contest

AdvancedProfile 2 | [Public Beta] MyTrader

Latest Releases: Password Change - Mark Unread - Ban Appeal

 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Banner rotation
Author Message
Svizy
Support Team

Support

Posts: 1,242
Joined: Aug 2009
Reputation: 6
Post: #1
 Banner rotation
I'm having some troubles with adding one more spot to the banner rotation code that I've found browsing the net.

This is the general code whic works just fine:

Rotation part? (guessing)
Code:
function random_banner(){
  var i=0;
  banners = new Array();
  banners[0] = '<IMG SRC="banner0.gif" WIDTH=400 HEIGHT=40>';
  banners[1] = '<IMG SRC="banner1.gif" WIDTH=400 HEIGHT=40>';
  banners[2] = '<IMG SRC="banner2.gif" WIDTH=400 HEIGHT=40>';
  today = new Date();
  i=today.getSeconds();
  n=banners.length;
  return banners[i-Math.round((i-1)/n)*n];
}
Display part (defenetly)
Code:
<SCRIPT LANGUAGE="JavaScript">
document.write(random_banner())
</SCRIPT>

Code works great (feel free to leech it ). But I don't have any clue how to add an another banner to the rotation, tried the most simple way whic didn't work.

Simple way that doesn't work
Code:
banners[3] = '<IMG SRC="banner3.gif" WIDTH=400 HEIGHT=40>';

I need help with this so that I can add at least 8 more banners (to have a nice round number 10)

Reward:

Solver will be rewarded with lifetime Svizy.net membership (yeah, I need to promote it a little) and with his sites banner being on two different locations (included in rotation and on svizy.net).

Note: If you already have an banner at svizy.net you'll recive MyBux payment istead (your add is already automaticly included in the rotator whic will be used on another site)!

Giving PM support only for General MyBB issues!

09-28-2009 11:13 PM


mastermunj
Senior Member


Posts: 519
Joined: Aug 2009
Reputation: 2
Post: #2
RE: Banner rotation
Try following...

Code:
function random_banner()
{
  banners = new Array();
  banners[0] = '<IMG SRC="banner0.gif" WIDTH=400 HEIGHT=40>';
  banners[1] = '<IMG SRC="banner1.gif" WIDTH=400 HEIGHT=40>';
  banners[2] = '<IMG SRC="banner2.gif" WIDTH=400 HEIGHT=40>';
  banners[3] = '<IMG SRC="banner3.gif" WIDTH=400 HEIGHT=40>';
  return banners[Math.floor(Math.random() * banners.length)];
}

If you wanna keep track of which banner got flashed how many times, then better switch to ajax + php combo...

[Image: LocalSearchTalksForum-AllForums.gif] [Image: PtcSquadForums-AllForums.1.gif]
(This post was last modified: 09-29-2009 12:02 AM by mastermunj.)
09-29-2009 12:01 AM
ghazal
Pluginer, Themer and MyCoder

Posts: 226
Joined: Jun 2009
Post: #3
RE: Banner rotation
Code:
function random_banner(){
  var i=0;
  banners = new Array();
  banners[0] = '<IMG SRC="banner0.gif" WIDTH=400 HEIGHT=40>';
  banners[1] = '<IMG SRC="banner1.gif" WIDTH=400 HEIGHT=40>';
  banners[2] = '<IMG SRC="banner2.gif" WIDTH=400 HEIGHT=40>';
banners[3] = '<IMG SRC="banner3.gif" WIDTH=400 HEIGHT=40>';
  today = new Date();
  i=today.getSeconds();
  n=banners.length;
  return banners[i-Math.round((i-1)/n)*n];
}

Did this ^^ works ?
09-29-2009 12:28 AM
mastermunj
Senior Member


Posts: 519
Joined: Aug 2009
Reputation: 2
Post: #4
RE: Banner rotation
@Ghazal.. nah, that won't work... he already tried it

it mainly reaches to index -1 which is why javascript error occurs

[Image: LocalSearchTalksForum-AllForums.gif] [Image: PtcSquadForums-AllForums.1.gif]
09-29-2009 12:46 AM
Svizy
Support Team

Support

Posts: 1,242
Joined: Aug 2009
Reputation: 6
Post: #5
RE: Banner rotation
(09-29-2009 12:01 AM)ptcsquad Wrote:  Try following...

Code:
function random_banner()
{
  banners = new Array();
  banners[0] = '<IMG SRC="banner0.gif" WIDTH=400 HEIGHT=40>';
  banners[1] = '<IMG SRC="banner1.gif" WIDTH=400 HEIGHT=40>';
  banners[2] = '<IMG SRC="banner2.gif" WIDTH=400 HEIGHT=40>';
  banners[3] = '<IMG SRC="banner3.gif" WIDTH=400 HEIGHT=40>';
  return banners[Math.floor(Math.random() * banners.length)];
}

If you wanna keep track of which banner got flashed how many times, then better switch to ajax + php combo...
Works like a charm now
Since your banner is already included I'll send you some MyBux istead

*moderator please close this thread since its solved *

Giving PM support only for General MyBB issues!

09-29-2009 12:56 AM
Alexandru21
Administrator



Posts: 584
Joined: Jun 2008
Reputation: 5
Post: #6
RE: Banner rotation
I can make a banner rotation plugin with MyPS enabled for banner packages and different locations. What do you think?

[Image: Alexandru21.png]
Create your free Twitter Signature.
09-29-2009 12:57 AM
Svizy
Support Team

Support

Posts: 1,242
Joined: Aug 2009
Reputation: 6
Post: #7
RE: Banner rotation
(09-29-2009 12:57 AM)Alexandru21 Wrote:  I can make a banner rotation plugin with MyPS enabled for banner packages and different locations. What do you think?
Awesome idea, but I would not be able to use it since I have an fixed place for the rotation. Good idea in general tough

Giving PM support only for General MyBB issues!

09-29-2009 12:58 AM
Alexandru21
Administrator



Posts: 584
Joined: Jun 2008
Reputation: 5
Post: #8
RE: Banner rotation
You (as Administrator) will choose the place(s) for the banners.

[Image: Alexandru21.png]
Create your free Twitter Signature.
09-29-2009 01:03 AM
Svizy
Support Team

Support

Posts: 1,242
Joined: Aug 2009
Reputation: 6
Post: #9
RE: Banner rotation
(09-29-2009 01:03 AM)Alexandru21 Wrote:  You (as Administrator) will choose the place(s) for the banners.
Ok, thats different Will be same as my code (see here: http://www.svizy-net.fi.st/ <--- just messing around, could not be even released )

Giving PM support only for General MyBB issues!

09-29-2009 01:05 AM
mastermunj
Senior Member


Posts: 519
Joined: Aug 2009
Reputation: 2
Post: #10
RE: Banner rotation
Alex, that would be an awesome plugin

We will wait for its release

[Image: LocalSearchTalksForum-AllForums.gif] [Image: PtcSquadForums-AllForums.1.gif]
09-29-2009 01:07 AM
 





Web Design | Web Design Jobs