Forum Moderators: open

Message Too Old, No Replies

Need help using two scripts on one page.

         

waydewest

4:58 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



I have the following two "copy and paste" javascripts that I would like to use on a single webpage, however there appears to be a conflict. The slideshow script works fine, but the floating menu script does not. I tried combining the Onload functions, but this did not help. I'm posting the two seperate scripts, if somebody could help me combine them I would truly appreciate it.

The first script (a slideshow)...

<script>
<!--
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 4000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'yweh1/h1cpl1.jpg'
Pic[1] = 'yweh1/h1cpl2.jpg'
Pic[2] = 'yweh1/h1cpl3.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans(duration=2)"
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
document.images.SlideShow.filters.blendTrans.Apply()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play()
}
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
//-->
</script>

</head>
<body>
<body onload="runSlideShow()">
<div id="wrap">

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="VU" height=280 width=300>
<img src="yweh1/h1cpl1.jpg" name='SlideShow' width=300 height=280></td>
</tr>
</table>

The second script (supposed to be a floating menu)...
<STYLE>
#floatingmenu {
Z-INDEX: 33; WIDTH: 125px; POSITION: absolute; TOP: 210px; LEFT: 675px; HEIGHT: 180px
}
</STYLE>

<SCRIPT language=JavaScript>
// ----------------------------------------
// Detectind user browser
// ----------------------------------------
var Nav = navigator, Ag = Nav.userAgent;
var bIE = (Ag.indexOf('MSIE') >= 0), bMacIE = false;
var bNC = (navigator.appName == "Netscape");
var bOpera = (Ag.indexOf('Opera') >= 0);
var nVer = 0, sTmp = "";
if (bIE) {
sTmp = Ag.substring(Ag.indexOf("MSIE") + 5, Ag.length);
nVer = Math.floor (sTmp.substring(0, sTmp.indexOf(";")));
if (nVer >= 4 &&!document.all)
nVer = 0;
if (Ag.indexOf("Mac") >= 0)
bMacIE = true;
}
if (bNC)
nVer = Math.floor (Nav.appVersion.substring (0, Nav.appVersion.indexOf (" ") ) );

bDynamic = (document.all ¦¦ document.layers)? true : false;

// ----------------------------------------
// Menu moving functions
// ----------------------------------------
nMenuYPos = 210;
nYDelta = 25;
nPrevScrollPos = 0;

function Spy () {
if (bNC && nVer >= 4) {
if (window.pageYOffset < nMenuYPos - nYDelta)
nNeededPos = nMenuYPos;
else
nNeededPos = window.pageYOffset + nYDelta;
nCurrentPos = document.layers["floatingmenu"].top;

if (nNeededPos == nCurrentPos)
return;

nCurrentPos += Math.round ( (nNeededPos - nCurrentPos) / 4);
document.layers["floatingmenu"].top = nCurrentPos;
}

if (bIE && nVer >= 4 &&!bMacIE) {
if (document.body.scrollTop < nMenuYPos - nYDelta)
nNeededPos = nMenuYPos;
else
nNeededPos = document.body.scrollTop + nYDelta;
nCurrentPos = document.all["floatingmenu"].offsetTop;

if (nNeededPos == nCurrentPos)
return;

nDelta = (nNeededPos - nCurrentPos) / 6;
if (nDelta > 0 && nDelta < 0.5)
nCurrentPos += nNeededPos - nCurrentPos;
else
if (nDelta < 0 && nDelta >= -0.5)
nCurrentPos --;
else
nCurrentPos += Math.round (nDelta);

pnt = document.all ["floatingmenu"].style;
pnt.top = nCurrentPos;
}
}

function ScriptStart () {
if (bNC && nVer >= 4)
setInterval ("Spy ()", 20);
if (bIE && nVer >= 4 &&!bMacIE)
setInterval("Spy ()", 20);
}

bScriptLoaded = true;
</SCRIPT>

<table width="770" height="215" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="125" align="left" valign="top">
<div id=floatingmenu>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
<tr><td><a href="index.html" onmouseover="document.homelink.src='ywelinks/linkhomea.gif'" onmouseout="document.homelink.src='ywelinks/linkhome.gif'"><img src="ywelinks/linkhome.gif" name="homelink" width="125" height="30" alt="Home" border="0"/></a></td></tr>
<tr><td><a href="peaceofmind.html" onmouseover="document.peaceofmindlink.src='ywelinks/linkpeaceofminda.gif'" onmouseout="document.peaceofmindlink.src='ywelinks/linkpeaceofmind.gif'"><img src="ywelinks/linkpeaceofmind.gif" name="peaceofmindlink" width="125" height="30" alt="Peace of Mind" border="0"/></a></td></tr>
<tr><td><a href="planning.html" onmouseover="document.planninglink.src='ywelinks/linkplanninga.gif'" onmouseout="document.planninglink.src='ywelinks/linkplanning.gif'"><img src="ywelinks/linkplanning.gif" name="planninglink" width="125" height="30" alt="Planning" border="0"/></a></td></tr>
<tr><td><a href="performance.html" onmouseover="document.performancelink.src='ywelinks/linkperformancea.gif'" onmouseout="document.performancelink.src='ywelinks/linkperformance.gif'"><img src="ywelinks/linkperformance.gif" name="performancelink" width="125" height="30" alt="Performance" border="0"/></a></td></tr>
<tr><td><a href="music.html" onmouseover="document.musiclink.src='ywelinks/linkmusica.gif'" onmouseout="document.musiclink.src='ywelinks/linkmusic.gif'"><img src="ywelinks/linkmusic.gif" name="musiclink" width="125" height="30" alt="Music" border="0"/></a></td></tr>
<tr><td><a href="experience.html" onmouseover="document.experiencelink.src='ywelinks/linkexperiencea.gif'" onmouseout="document.experiencelink.src='ywelinks/linkexperience.gif'"><img src="ywelinks/linkexperience.gif" name="experiencelink" width="125" height="30" alt="Experience" border="0"/></a></td></tr>
</table></div>
</td>
</tr>
</table>

Fotiman

9:33 pm on Jul 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your second snippet of code looks like nothing is trying to start the script. Try this:

<body onload="runSlideShow();ScriptStart();">

A better method would be to call each of these methods in an unobtrusive way (ie. - not as the onload attribute of the body element). But to get you running, try my example above.