Web Analytics Made Easy -
StatCounter Making 2 scripts work on the same page... - CodingForum

Announcement

Collapse
No announcement yet.

Making 2 scripts work on the same page...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making 2 scripts work on the same page...

    Ok, I read the tutorial and I understand what the problem is, but I can't seem to remedy it. I think the easiest way for someone to help me is if I just paste the code and someone could repaste it corrected. Here it is:

    Script 1

    <script language="javascript">
    /*******************************************
    Vertical Scroller (Marquee Replacement) v-1.3
    Brian Gosselin - http://scriptasylum.com

    Version notes:
    V-1.0: Initial release.
    V-1.1: Fixed bug in NS6 where page shrinks and grows as
    content scrolls. You no longer have to specify
    content height, the script does this for you.
    V-1.2: Fixed a bug in NS4 where scrolling content would
    dictate the bottom boundary of box script.
    V-1.3: Added selectable support for pausing the scrolling
    when box moused-over.
    *******************************************/

    //ENTER CONTENT TO SCROLL BELOW.
    var content='text goes here ';

    var boxheight=185; // BACKGROUND BOX HEIGHT IN PIXELS.
    var boxwidth=250; // BACKGROUND BOX WIDTH IN PIXELS.
    var boxcolor="#000000"; // BACKGROUND BOX COLOR.
    var speed=50; // SPEED OF SCROLL IN MILLISECONDS (1 SECOND=1000 MILLISECONDS)..
    var pixelstep=1; // PIXELS "STEPS" PER REPITITION.
    var godown=false; // TOP TO BOTTOM=TRUE , BOTTOM TO TOP=FALSE
    var pauseOnmouseover=false; //SET TO "true" TO ENABLE PAUSE WHEN MOUSEOVER, "false" TO DISABLE IT.

    // 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='';
    var goscroll=true;
    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+' '+((pauseOnmouseover)? 'onmouseover="goscroll=false" onmouseout="goscroll=true"':'')+'>';
    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" '+((pauseOnmouseover)? 'onmouseover="goscroll=false" onmouseout="goscroll=true"':'')+'>';
    txt+='<div id="inner" style="position:absolute; visibility:hidden; left:2px; top:2px; width:'+(boxwidth-4)+'; overflow:hidden; cursor:default;" '+((pauseOnmouseover)? 'onmouseover="goscroll=false" onmouseout="goscroll=true"':'')+'>'+content+'</div>';
    txt+='</div>';
    }
    document.write(txt);
    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)arseInt(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(goscroll){
    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";
    inner.style.visibility="visible";
    }
    setInterval('scrollbox()',speed);
    }

    </script>

    Script 2

    <script language="javascript">


    // ENTER TEXT BELOW. CAN *NOT* INCLUDE NORMAL HTML CODE.
    var text='ANY TEXT HERE...';
    window.onload=function()
    var delay=40; // SPEED OF TRAIL
    var Xoff=0; // PIXEL COUNT FROM THE LEFT OF THE CURSOR (- VALUES GO TO LEFT)
    var Yoff=-30; // PIXEL COUNT FROM THE TOP OF THE CURSOR (- VALUES GO UP)
    var txtw=14; // AMOUNT OF PIXEL SPACE EACH CHARACTER OCCUPIES
    var beghtml='<font color="#00436e"><b>'; // OPTIONAL HTML CODE THAT EFFECTS WHOLE TEXT STRING SUCH AS FONT COLOR, SIZE, ETC.
    var endhtml='</b></font>'; // END HTML CODE. MOSTLY USED IF ABOVE SETTING IS USED.

    //********** NO NEED TO EDIT BELOW HERE **********\\

    ns4 = (navigator.appName.indexOf("Netscape")>=0 && document.layers)? true : false;
    ie4 = (document.all && !document.getElementById)? true : false;
    ie5 = (document.all && document.getElementById)? true : false;
    ns6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
    var txtA=new Array();
    text=text.split('');
    var x1=0;
    var y1=-1000;
    var t='';

    for(i=1;i<=text.length;i++){
    t+=(ns4)? '<layer name="txt'+i+'" top="-100" left="0" width="'+txtw+'" height="1">' : '<div id="txt'+i+'" style="position:absolute; top:-100px; left:0px; height:1px; width:'+txtw+'; visibility:visible;">';
    t+=beghtml+text[i-1]+endhtml;
    t+=(ns4)? '</layer>' : '</div>';
    }
    document.write(t);

    function moveid(id,x,y){
    if(ns4)id.moveTo(x,y);
    else{
    id.style.left=x+'px';
    id.style.top=y+'px';
    }}

    function animate(evt){
    x1=Xoff+((ie4||ie5)?event.clientX+document.body.scrollLeft:evt.pageX);
    y1=Yoff+((ie4||ie5)?event.clientY+document.body.scrollTop:evt.pageY);
    }

    function getidleft(id){
    if(ns4)return id.left;
    else return parseInt(id.style.left);
    }

    function getidtop(id){
    if(ns4)return id.top;
    else return parseInt(id.style.top);
    }

    function getwindowwidth(){
    if(ie4||ie5)return document.body.clientWidth+document.body.scrollLeft;
    else return window.innerWidth+pageXOffset;
    }

    function movetxts(){
    for(i=text.length;i>1;i=i-1){
    if(getidleft(txtA[i-1])+txtw*2>=getwindowwidth()){
    moveid(txtA[i-1],0,-1000);
    moveid(txtA[i],0,-1000);
    }else moveid(txtA[i], getidleft(txtA[i-1])+txtw, getidtop(txtA[i-1]));
    }
    moveid(txtA[1],x1,y1);
    }

    window.onload=function(){
    for(i=1;i<=text.length;i++)txtA[i]=(ns4)?document.layers['txt'+i]ie4)?document.all['txt'+i]:document.getElementById('txt'+i);
    if(ns4)document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove=animate;
    setInterval('movetxts()',delay);
    }
    </script>

  • #2
    There is an onload conflict. There are many threads regarding that. Checkout my sig.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      I have checked your sig out and read the other threads and many are similar to mine.... although, it still isn't all that clear. If someone could show me exactly what it should look like, or show me a thread that has the before and after, I would really appreciate it..

      The biggest problem that I have is knowing which window.onload lines to delete and where the resolution line is supposed to go.. Is the resolution line supposed to replace the window.onload lines?

      Comment


      • #4
        You should combine your onloads.

        Name your onload functions by changing the 2 onload function declarations:

        window.onload=function(){

        into named functions:

        function doLoad1(){

        and

        function doLoad2(){


        and then setting new onload handler like:

        window.onload=function(){doLoad1();doLoad2()};
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Where does the new onload handler go? Above the first script?

          Comment


          • #6
            You can put it anywhere outside any function. But it's good to put it below your scripts.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              Glenn, I can't thank you enough!! Sorry for being difficult... I got it to work finally!! THANK YOU!!

              One more quick question, If I was to add another, I would just name it doLoad 3? and so on, as long as I also add it to the onload handler.

              Comment


              • #8
                Glad I could be of help

                Yes. But you can name it with descriptive names too.
                Glenn
                vBulletin Mods That Rock!

                Comment

                Working...
                X