How to link an external Div scroller script..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leet
    New Member
    • Apr 2010
    • 4

    How to link an external Div scroller script..

    I have used a piece of javascript code to scroll the main content of my website, this works well but I want to externally import from a javascript file format.I have tried many ways for the solution of this problem but have not managed to solve it . below is the javascript source code and the HTML that I will be using it in.

    JavaScript code:
    Code:
    <script type="text/javascript">
    
    scrollStep=3
    
    timerUp=""
    timerDown=""
    
    function toTop(id){
    document.getElementById(id).scrollTop=0
    }
    
    function scrollDivDown(id){
    clearTimeout(timerDown) 
    document.getElementById(id).scrollTop+=scrollStep
    timerDown=setTimeout("scrollDivDown('"+id+"')",5)
    }
    
    function scrollDivUp(id){
    clearTimeout(timerUp)
    document.getElementById(id).scrollTop-=scrollStep
    timerUp=setTimeout("scrollDivUp('"+id+"')",10)
    }
    
    function toBottom(id){
    document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
    }
    
    function stopMe(){
    clearTimeout(timerDown) 
    clearTimeout(timerUp)
    }
    
    </script>


    HTML
    ========
    Code:
    <div id="scroll">
    <a onclick="toTop('container')"> Top </a> 
    <a onmouseover="javascript:scrollDivDown('container');" onmouseout="stopMe();"> Scroll Down </a> 
    <a onmouseover="scrollDivUp('container')" onmouseout="stopMe()"> Scroll Up </a>
    <a onclick="toBottom('container')"> Bottom </a>
    </div>
    (container is the div that is to be scrolled)


    I would appreciate your help very much on how to link this code externally..

    Thanks :)

    - L33T(leet)
    Last edited by Dormilich; Apr 8 '10, 05:48 PM. Reason: Java != JavaScript
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you mean something like
    Code:
    <script type="text/javascript" src="file.js"></script>
    ?

    Comment

    • leet
      New Member
      • Apr 2010
      • 4

      #3
      Oddly enough I have tried that.. but it still does not work :(.. I am pretty suck for ideas..

      EDIT
      =====

      I've opened up the js file in Dreamweaver CS4.. and it states that there is a syntax error in line 14..

      Code:
      <script type="text/javascript">
      
      scrollStep=3
      
      timerUp=""
      timerDown=""
      
      function toTop(id){
      document.getElementById(id).scrollTop=0
      }
      
      function scrollDivDown(id){
      clearTimeout(timerDown) 
      [U][B]document.getElementById(id).scrollTop+=scrollStep[/B][/U]
      timerDown=setTimeout("scrollDivDown('"+id+"')",5)
      }
      
      function scrollDivUp(id){
      clearTimeout(timerUp)
      document.getElementById(id).scrollTop-=scrollStep
      timerUp=setTimeout("scrollDivUp('"+id+"')",10)
      }
      
      function toBottom(id){
      document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
      }
      
      function stopMe(){
      clearTimeout(timerDown) 
      clearTimeout(timerUp)
      }
      
      </script>
      Any reason why this is ?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        first I’d try setting the semi-colons (command limiter). then I’d try
        Code:
        timerUp = setTimeout(scrollDivUp, 10, id);

        Comment

        Working...