Click here to Skip to main content

Getting scrollbar height&width

function GetSBSize(){ var i = document.createElement('p'); i.style.width = '100%'; i.style.height = '200px'; var o = document.createElement('div'); o.style.position = 'absolute'; o.style.top = '0px'; o.style.l
Sign Up to vote bad good
Add a reason or comment to your vote: x
Votes of 3 or less require a comment
See more: Javascript
function GetSBSize(){
            var i = document.createElement('p');
            i.style.width = '100%';
            i.style.height = '200px';
            var o = document.createElement('div');
            o.style.position = 'absolute';
            o.style.top = '0px';
            o.style.left = '0px';
            o.style.visibility ='hidden';
            o.style.width = '200px';
            o.style.height = '150px';
            o.style.overflow = 'hidden';
            o.appendChild(i);
            document.body.appendChild(o);
            var w1 = i.offsetWidth;
            var h1 = i.offsetHeight;
            o.style.overflow = 'scroll';
            var w2 = i.offsetWidth;
            var h2 = i.offsetHeight;
            if (w1 == w2) w2 = o.clientWidth;
            if (h1 == h2) h2 = o.clientWidth;
            document.body.removeChild(o);
            //assing to window object
            window.scrollbarWidth = w1 - w2;
            window.scrollbarHeight = h1 - h2; 
}
Posted 22 Nov '09
yozi823
Edited 22 Nov '09


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Your Filters
Interested
Ignored
     
  1. Wonde Tadesse (1,120)
  2. SAKryukov (438)
  3. aniketyadav7 (145)
  1. SAKryukov (9,722)
  2. Christian Graus (6,019)
  3. OriginalGriff (4,736)
  4. thatraja (4,349)
  5. Abhinav S (4,345)

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --

Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 23 Nov 2009
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid