Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    0
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java Script in page.

    I am trying to condense my page script and have a long Java Script to make a section scrolling.

    What I want to do is put that script in a single file and have the page load it. Make sense?


    THis is placed before the content

    Code:
    <div id="marqueecontainer" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">
    <div id="vmarquee" style="position: absolute; width: 98%;">
    and this after content I want to scroll.

    Code:
        <script  type="text/javascript">
    /*<![CDATA[*/
    function Marquee(o){
     var oop=this,obj=document.getElementById(o.ID),top=0;
     var marquee=obj.getElementsByTagName('DIV')[0];
     this.marqueeheight=marquee.offsetHeight;
     marquee.style.top=-this.marqueeheight+'px';
    
     this.marquee=[marquee];
     while (top<obj.offsetHeight){
      marquee=marquee.cloneNode(true);
      marquee.style.top=top+'px';
      obj.appendChild(marquee);
      this.marquee.push(marquee);
      top+=this.marqueeheight;
     }
    
     this.Speed=o.marqueespeed;
     setTimeout(function(){ setInterval(function(){ oop.scroll(); },30); }, o.delayb4scroll)
    }
    
    Marquee.prototype.scroll=function(){
     for (var top,z0=0;z0<this.marquee.length;z0++){
      top=parseInt(this.marquee[z0].style.top)-this.Speed
      this.marquee[z0].style.top=top+"px";
      if (top<-this.marqueeheight){
       this.marquee[z0].style.top=top+this.marqueeheight*this.marquee.length+"px";
      }
     }
    }
    
    /*]]>*/
    </script>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var M1=new Marquee({
     ID:'marqueecontainer',
     delayb4scroll:10000, //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
     marqueespeed:1 //Specify marquee scroll speed (larger is faster 1-10)
    });
    
    
    var M2=new Marquee({
     ID:'marqueecontainer2',
     delayb4scroll:2000, //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
     marqueespeed:1 //Specify marquee scroll speed (larger is faster 1-10)
    });
    
    
    /*]]>*/
    </script>
    There is a CSS file I made that controls the style of the script. it is as follows just in case the information is needed.

    Code:
    #marqueecontainer{
    position: relative;
    width: 400px; /*marquee width */
    height: 500px; /*marquee height */
    background-color: #333333;
    overflow: hidden;
    border: 3px #8e0406;
    padding: 2px;
    padding-left: 4px;
    }
    
    #marqueecontainer2{
    position: relative;
    width: 400px; /*marquee width */
    height: 500px; /*marquee height */
    background-color: #333333;
    overflow: hidden;
    border: 3px #8e0406;
    padding: 2px;
    padding-left: 4px;
    I would like to have the JAVA script on a single .js file and have the file used instead of having the load of script in my footer.php file.

    My website is Richard Tamm | Photography & Writing In case it is if any assistance.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Place your Javascript code (without any HTML - <script> tags) in a separate external file and call it with

    <script type = "text/javascript" src="myscriptname.js"></script>

    You should place this right in front of closing </BODY> tag.

    Quizmaster: According to the song, which means of transport did Bonnie Prince Charlie use to escape to the Isle of Skye?
    Contestant: A horse.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    LinkBacks (?)

    1. 02-22-2014, 10:44 AM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •