Monday, February 20, 2012

Set Div Scroll bar postion by code.

Hi in follwoing example we set the div scrollbar postion by passing predefined value. we can calculate this value depend on our requirement.
How to retrive current scroll top of div?
Add follwoing event in div
Implement function and store scrolltop in hiddenfield.
function MaintanDivScrollPosition(sender) {"input[type=hidden][id$=HiddenFieldScrollTopDivContentPage]").val($(sender)[0].scrollTop);


        <title>OnScroll Example</title>
        <script type="text/javascript">
            function CallOnLoad () {
               document.getElementById("divrelative").scrollTop = 500;
    <body onload="CallOnLoad()">
        <div id="divrelative" style="overflow:scroll;height:200px;">
         <P>Line 1</p>
         <P>Line 2</p>
         <P>Line 3</p>
         <P>Line 4</p>
         <P>Line 5</p>
         <P>Line 6</p>
         <P>Line 7</p>
         <P>Line 8</p>
         <P>Line 9</p>
         <P>Line 10</p>
         <P>Line 11</p>
         <P>Line 12</p>
   <P>Line 14</p>
         <P>Line 15</p>
         <P>Line 16</p>
         <P>Line 17</p>
         <P>Line 18</p>
         <P>Line 19</p>
         <P>Line 20</p>
         <P>Line 21</p>
         <P>Line 22</p>

No comments: