PDA

View Full Version : I want to combine TWO scripts on a single page..



ptlruler
01-15-2005, 04:50 PM
I am having trouble having two scripts work together on the same page. The FAQ section had some info regarding this but didnt seem to help me...

The first script is the main navigation dropdown menu in the header of my page...heres the snippet of code that goes in the HEAD....

<link href="CascadeMenu.css" rel="stylesheet">
<script language="javascript" src="CascadeMenu.js">
</script>


Heres the ONLOAD event handler.....

<BODY OnLoad="InitMenu(menuBar)" Onclick="HideMenu(menuBar)" ID="Bdy" bgColor=white>



The second script I'd like to run is a simple vertical scroller menu. There is nothing required in the HEAD of the page codewise and there is no ONLOAD event handler that I can see. The scroller is one of those "copy-and-past-this-where-you-want-the-scroller-to-appear" type things.

Heres the script for the scroller.....

<!--webbot bot="HTMLMarkup" startspan --><script language="javascript">


//BEGIN SCROLLER SCRIPT

//ENTER CONTENT TO SCROLL BELOW.
var content='<p>Peoples Trailor Fantasy Football League</p><br><p>Peoples Trailor Fantasy Football League</p><br><p>Peoples Trailor Fantasy Football League</p><br><p>Peoples Trailor Fantasy Football League</p>';

var boxheight=180; // BACKGROUND BOX HEIGHT IN PIXELS.
var boxwidth=160; // BACKGROUND BOX WIDTH IN PIXELS.
var boxcolor="#999999"; // BACKGROUND BOX COLOR.
var speed=120; // SPEED OF SCROLL IN MILLISECONDS (1 SECOND=1000 MILLISECONDS)..
var pixelstep=2; // PIXELS "STEPS" PER REPITITION.
var godown=false; // TOP TO BOTTOM=TRUE , BOTTOM TO TOP=FALSE

// DO NOT EDIT BEYOND THIS POINT

var outer,inner,elementheight,ref,refX,refY;
var w3c=(document.getElementById)?true:false;
var ns4=(document.layers)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
var txt='';
if(ns4){
txt+='<table cellpadding=0 cellspacing=0 border=0 height='+boxheight+' width='+boxwidth+'><tr><td>';
txt+='<ilayer name="ref" bgcolor="'+boxcolor+'" width='+boxwidth+' height='+boxheight+'></ilayer>';
txt+='</td></tr></table>'
txt+='<layer name="outer" bgcolor="'+boxcolor+'" visibility="hidden" width='+boxwidth+' height='+boxheight+'>';
txt+='<layer name="inner" width='+(boxwidth-4)+' height='+(boxheight-4)+' visibility="hidden" left="2" top="2" >'+content+'</layer>';
txt+='</layer>';
}else{
txt+='<div id="ref" style="position:relative; width:'+boxwidth+'; height:'+boxheight+'; background-color:'+boxcolor+';" ></div>';
txt+='<div id="outer" style="position:absolute; width:'+boxwidth+'; height:'+boxheight+'; visibility:hidden; background-color:'+boxcolor+'; overflow:hidden" >';
txt+='<div id="inner" style="position:absolute; visibility:visible; left:2px; top:2px; width:'+(boxwidth-4)+'; overflow:hidden; cursor:default;">'+content+'</div>';
txt+='</div>';
}
document.write(txt);

function getElHeight(el){
if(ns4)return (el.document.height)? el.document.height : el.clip.bottom-el.clip.top;
else if(ie4||ie5)return (el.style.height)? el.style.height : el.clientHeight;
else return (el.style.height)? parseInt(el.style.height):parseInt(el.offsetHeight);
}

function getPageLeft(el){
var x;
if(ns4)return el.pageX;
if(ie4||w3c){
x = 0;
while(el.offsetParent!=null){
x+=el.offsetLeft;
el=el.offsetParent;
}
x+=el.offsetLeft;
return x;
}}

function getPageTop(el){
var y;
if(ns4)return el.pageY;
if(ie4||w3c){
y=0;
while(el.offsetParent!=null){
y+=el.offsetTop;
el=el.offsetParent;
}
y+=el.offsetTop;
return y;
}}

function scrollbox(){
if(ns4){
inner.top+=(godown)? pixelstep: -pixelstep;
if(godown){
if(inner.top>boxheight)inner.top=-elementheight;
}else{
if(inner.top<2-elementheight)inner.top=boxheight+2;
}}else{
inner.style.top=parseInt(inner.style.top)+((godown)? pixelstep: -pixelstep)+'px';
if(godown){
if(parseInt(inner.style.top)>boxheight)inner.style.top=-elementheight+'px';
}else{
if(parseInt(inner.style.top)<2-elementheight)inner.style.top=boxheight+2+'px';
}}}

window.onresize=function(){
if(ns4)setTimeout('history.go(0)', 400);
else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
}}

window.onload=function(){
outer=(ns4)?document.layers['outer']:(ie4)?document.all['outer']:document.getElementById('outer');
inner=(ns4)?outer.document.layers['inner']:(ie4)?document.all['inner']:document.getElementById('inner');
ref=(ns4)?document.layers['ref']:(ie4)?document.all['ref']:document.getElementById('ref');
elementheight=getElHeight(inner);
if(ns4){
outer.moveTo(getPageLeft(ref),getPageTop(ref));
outer.clip.width=boxwidth;
outer.clip.height=boxheight;
inner.top=(godown)? -elementheight : boxheight-2;
inner.clip.width=boxwidth-4;
inner.clip.height=elementheight;
outer.visibility="show";
inner.visibility="show";
}else{
outer.style.left=getPageLeft(ref)+'px';
outer.style.top=getPageTop(ref)+'px';
inner.style.top=((godown)? -elementheight : boxheight)+'px';
inner.style.clip='rect(0px, '+(boxwidth-4)+'px, '+(elementheight)+'px, 0px)';
outer.style.visibility="visible";
}
setInterval('scrollbox()',speed);
}
</script>

<!--webbot bot="HTMLMarkup" endspan -->



Does anyone have any suggestions for making this work? I'm sure this should be easy for the code specialists out there. I am novice and cant seem to make it work.

Thanks for any help you may offer.

simonf
01-17-2005, 04:36 AM
Hi

Do you have a page link where it's not working, because this should be able to work.

Minos
01-18-2005, 07:02 AM
It should, unless you have a couple variable names that are the same between the two scripts...

And, having just barely glanced at it, if that window.onload isn't conflicting with that <body onLoad>...which I believe it very well may...

martinterry
01-19-2005, 03:47 PM
try removing the OnLoad="InitMenu(menuBar)" from the body tag and then add it later ( at the end of your script after the

setInterval('scrollbox()',speed);
}

InitMenu(menuBar)"

poohster
01-14-2008, 09:36 AM
hi im having the same problem :confused: heres the link

http://www.datzcreationzweddingstationery.co.uk/wedding%20stationery/portfolio/dasiy%20box%20favour2.htm

some image wont show as i havnt uploaded them yet

poohster
01-22-2008, 12:08 PM
:)i have now sorted it thanks