SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do i make a scrolling div always start at the top ?

    hello,

    how do i make a scrolling div always start at the top ?

    i have used the code from this post :i works great but when i refresh the page it does not go back to the top of the div (the latest post)

    this is the code :

    HTML Code:
    
     <!-- HOME HOME TWITTER SCROLL UP / DOWN -->
    	$(function() {
        var ele   = $('#scroll');
        var speed = 50, scroll = 5, scrolling;
        
        $('#sw-up').mouseenter(function() {
            // Scroll the element up
            scrolling = window.setInterval(function() {
                ele.scrollTop( ele.scrollTop() - scroll );
            }, speed);
        });
        
        $('#sw-down').mouseenter(function() {
            // Scroll the element down
            scrolling = window.setInterval(function() {
                ele.scrollTop( ele.scrollTop() + scroll );
            }, speed);
        });
        
        $('#sw-up, #sw-down').bind({
            click: function(e) {
                // Prevent the default click action
                e.preventDefault();
            },
            mouseleave: function() {
                if (scrolling) {
                    window.clearInterval(scrolling);
                    scrolling = false;
                }
            }
        });
    });	
    	

    thanks
    ricky

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    The code should do that automatically, that is to say that there is nothing in the code you posted which would cause the behaviour you describe.

    Could you therefore post a bit more code so that I can recreate your problem and/or a link to your page.

    In the worst case you can just set scrollTop of the appropriate div to zero on page load.


Bookmarks

Posting Permissions

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