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 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2007
    Location
    Latvia, Europe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Scroll down a div

    Hello. i'm making a chat for my homepage and i am making it ajaxed so i need to know how to scroll down a div. i found an CSS atribute overflow: auto; but i don't know how to make it scroll down. when i was making non-ajax chat i used iframe and then it wasn't a problem but now with div i have no idea how to do it.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Apr 2007
    Location
    Latvia, Europe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no i didn't wanted it to scroll down all the time. i just wanted it to scroll down on page load till bottom and that's all

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Than grab out the code that scrolls it to the bottom. You can do it!

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    New Coder
    Join Date
    Apr 2007
    Location
    Latvia, Europe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm it can't even seem to work without me in action. did i do something wrong?
    Code:
    <html>
    <head>
    <script type="text/javascript"> 
    
      var chatscroll = new Object();
    
      chatscroll.Pane = function(scrollContainerId){
        this.bottomThreshold = 20;
        this.scrollContainerId = scrollContainerId;
        this._lastScrollPosition = 100000000;
      }
    
      chatscroll.Pane.prototype.activeScroll = function(){
    
        var _ref = this;
        var scrollDiv = document.getElementById(this.scrollContainerId);
        var currentHeight = 0;
        
        var _getElementHeight = function(){
          var intHt = 0;
          if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight;
          else intHt = scrollDiv.offsetHeight;
          return parseInt(intHt);
        }
    
        var _hasUserScrolled = function(){
          if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null){
            return false;
          }
          return true;
        }
    
        var _scrollIfInZone = function(){
          if( !_hasUserScrolled || 
              (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){
              scrollDiv.scrollTop = currentHeight;
              _ref._isUserActive = false;
          }
        }
    
    
        if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight;
        else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight;
    
        _scrollIfInZone();
    
        _ref = null;
        scrollDiv = null;
    
      }
      var divScroll = new chatscroll.Pane('scroll');
    </script>
    </head>
    <body>
    <div onclick="divScroll.activeScroll();" id="scroll" style="overflow: auto; background : #000000; color : #ffffff; padding : 4px; width : 200px; height : 50px; ">
    1<br />
    2<br />
    3<br />
    4<br />
    5<br />
    6<br />
    7<br />
    8<br />
    9<br />
    10<br />
    </div>
    </body>
    </html>
    if it's something wrong there tell me

    EDIT: ok i looked down and i saw a code to scroll down and i midified it ad voila :
    Code:
    function scrooldown(div)
    {
        var scrollDiv       = document.getElementById(div);
        scrollDiv.scrollTop = scrollDiv.scrollHeight;
        scrollDiv           = null;
    }
    Last edited by BenX; 06-19-2007 at 03:59 PM. Reason: Found by myself

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you send me the full code. i don't get it to work.
    but im still a noob


  •  

    Posting Permissions

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