Connecting Tech Pros Worldwide Help | Site Map

Needs a urgent help with a rotating banner javascript code.

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 10th, 2006, 05:55 AM
sgMuser
Guest
 
Posts: n/a
Default Needs a urgent help with a rotating banner javascript code.

Hi,
I am not a good developer of Javascript codes. Needs this help to make
some modification to this famous free javascript from Anarchos. i am
using this in one of my webpage. What it does is, rotates banners with
hyperlink specific to each image. it works just perfect but i need a
simple modification. now I want to stop rotating the images when I
mouseover on the image, and then continue once I move the cursor out of
the banner image. Any one can help me please? Thanks in adv.

Rgds
RajSB


-----------the following code resides in a separate .js
file------------------

/****
* Banner Ad Rotater v3.02
* Anarchos > anarchos3@hotmail.com
* http://anarchos.xs.mw/bannerad.phtml
**/

function Banner(refreshTime, width, height, altText, start, random){
this.objName = "bannerAd" + (Banner.count++);
eval(this.objName + "=this");
if (!refreshTime) this.refreshTime = 5000; else this.refreshTime =
refreshTime*1000;
if (!width) this.width = 460; else this.width = width;
if (!height) this.height = 68; else this.height = height;
if (random == null) this.random = 1; else this.random = random;
this.altText = altText;
this.ads = [];
if (start) this.currentAd = start-1; else start = null;
this.mySize = 0;

this.Ad = function(src, href, target, mouseover) {
var tempImage = new Image();
tempImage.src = src;
this.ads[this.mySize] = new Object();
var ad = this.ads[this.mySize];
ad.src = src;
if (typeof(target) == "undefined" || target == null) ad.target =
"_self"; else ad.target = target;
ad.href = href;
ad.mouseover = mouseover;
this.mySize++;
}

this.link = function(){
var ad = this.ads[this.currentAd];
if (ad.target == "_self"){
location.href = ad.href;
}
else if (ad.target == "_blank" || ad.target == "_new"){
open(ad.href,this.objName + "Win");
}
else top.frames[ad.target].location.href = ad.href;
}

this.showStatus = function(){
var ad = this.ads[this.currentAd];
if (ad.mouseover) status = ad.mouseover;
else status = ad.href;
}

this.randomAd = function(){
var n;
do { n = Math.floor(Math.random() * (this.mySize)); }
while(n == this.currentAd);
this.currentAd = n;
}

this.output = function(){
var tempCode = "";
if (this.mySize > 1){
if (this.currentAd == null) this.randomAd();
if (this.currentAd >= this.mySize) this.currentAd = this.mySize - 1;
tempCode = '<a href="javascript:'+this.objName+'.link();"';
tempCode += ' onMouseOver="' + this.objName + '.showStatus(); return
true"';
tempCode += ' onMouseOut="status=\'\';return true">';
tempCode += '<img src="' + this.ads[this.currentAd].src + '"
width="' + this.width;
tempCode += '" name="' + this.objName + 'Img" height="' +
this.height + '" ';
if (this.altText) tempCode += 'alt="'+this.altText + '" ';
tempCode += 'border="0" /></a>';
document.write(tempCode);
this.nextAd();
} else document.write("Error: two banners must be defined for the
script to work.");
}

this.newAd = function(){
if (!this.random){
this.currentAd++;
if (this.currentAd >= this.mySize)
this.currentAd = 0;
}
else {
this.randomAd();
}
this.nextAd();
}

this.nextAd = function(){
document.images[this.objName+ 'Img'].src =
this.ads[this.currentAd].src;
setTimeout(this.objName+'.newAd()',this.refreshTim e)
}
}
Banner.count = 0;


----the following code to be embedded in a html page-----------

<script type="text/javascript">
// Author: Anarchos > anarchos3@hotmail.com >
http://anarchos.xs.mw/bannerad.phtml
<!--
myAd = new Banner( 5, 600, 100, "", 1, 0 );
myAd.Ad( "images/1.gif", "http://www.google.com", null, "Google" );
myAd.Ad( "images/2.gif", "http://www.yahoo.com", "_blank", "Yahoo.Com"
);
myAd.Ad( "images/3.gif", "http://www.msn.com", "_blank", "MSN.com" );
myAd.output();
// -->
</script>


  #2  
Old May 10th, 2006, 03:35 PM
McKirahan
Guest
 
Posts: n/a
Default Re: Needs a urgent help with a rotating banner javascript code.

"sgMuser" <rajvbs@gmail.com> wrote in message
news:1147240017.094784.102130@g10g2000cwb.googlegr oups.com...[color=blue]
> Hi,
> I am not a good developer of Javascript codes. Needs this help to make
> some modification to this famous free javascript from Anarchos. i am
> using this in one of my webpage. What it does is, rotates banners with
> hyperlink specific to each image. it works just perfect but i need a
> simple modification. now I want to stop rotating the images when I
> mouseover on the image, and then continue once I move the cursor out of
> the banner image. Any one can help me please? Thanks in adv.[/color]

Here's a solution:

1) Declare this variable:
var running = true;

2) Insert this line:
this.stopStart();
in this function:
this.showStatus = function() {

3) Add this function:
this.stopStart = function() {
(running) ? running = false : running = true;
if (running) this.nextAd();
else status = "";
}

4) Change this line
tempCode += ' onMouseOut="status=\'\';return true">';
to this:
tempCode += ' onMouseOut="' + this.objName + '.stopStart();
return true">';

5) Enclose the logic in
this.newAd = function() {
with:
if (running) {
}


  #3  
Old May 12th, 2006, 03:15 AM
sgMuser
Guest
 
Posts: n/a
Default Re: Needs a urgent help with a rotating banner javascript code.

McKirahan
Out of words to thank you! God Bless You! It works!

Rgds
RajSB

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.