element.scrollTop - odd behavior

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    element.scrollTop - odd behavior

    Using FireFox 19.0.2

    I have noticed that when I set .scrollTop = 0, the content is indeed loaded showing the top of the content.

    However the scroll bar, is left at the location where it was when last viewed.

    How can I make sure that both the content and the scroll bar (slider) are set to 0 (top of container)?

    The content is contained in a <div> tag. Within the container is a table that exceeds the max height of the container.
    Code:
    					<div 
    						id="scratchPad" 
    						style=" position:relative;
    								top:25px;
    								margin-left:auto;
    								margin-right:auto;	
    								border:5px ridge #ff6600; 
    								padding:7px;
    								background-color: #ccffcc; 
    								background-image:linear-gradient(to top, #ccff99 0%, White 100%);
    								height:75%;
    								width:65%;
    								visibility:hidden;
    								overflow: scroll;
    								z-index: 101;"
    					>
    						<table style="display: flex;margin: auto;opacity:0.85;">
    
    
    	document.getElementById("scratchPad").scrollTop = 0;
    	document.getElementById("scratchPad").style.visibility = "visible";
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Upon further review, this odd behavior only happens when I reload the page.

    If I close and reopen the <div> node with javaScript, the slider is correctly reset to the top of the scroll bar.

    Still odd that this should happen and would be curious to know if this is a known bug?

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Hi Claus
      have you tried using the jquery method,
      Code:
      <div 
                                  id="scratchPad" 
                                  style=" position:relative;
                                          top:25px;
                                          margin-left:auto;
                                          margin-right:auto;    
                                          border:5px ridge #ff6600; 
                                          padding:7px;
                                          background-color: #ccffcc; 
                                          background-image:linear-gradient(to top, #ccff99 0%, White 100%);
                                          height:75%;
                                          width:65%;
                                          visibility:hidden;
                                          overflow: scroll;
                                          z-index: 101;"
                              >
                                  <table style="display: flex;margin: auto;opacity:0.85;">     
       <script>
      $("#scratchPad").scrollTop(0);
      $("#scratchPad").fadeOut(slow);
      </script>
      regards,
      Omer Aslam

      Comment

      • Claus Mygind
        Contributor
        • Mar 2008
        • 571

        #4
        Omer, thanks for your reply.

        I do not believe in jQuery for a number of reasons.

        Comment

        Working...