2009-12-10 7 views

Répondre

1
window.scrollBarWidth = function() { 
    document.body.style.overflow = 'hidden'; 
    var width = document.body.clientWidth; 
    document.body.style.overflow = 'scroll'; 
    width -= document.body.clientWidth; 
    if(!width) width = document.body.offsetWidth - document.body.clientWidth; 
    document.body.style.overflow = ''; 
    return width; 
} 
+0

Est-ce que cela fonctionne bien avec les croisés? Sous quel navigateur ce code a-t-il été testé? – marcgg

2

Il n'y a aucun moyen de travail cross navigateur (IE est le problème, comme toujours), désolé

+1

Je ne crois pas qu'il y ait aucun moyen. –

0

Voici un exemple MooTools, et je viens de finir série complète de tests multi-navigateur.

http://jsfiddle.net/jP6q2/2/

Longue histoire courte:

var body = $$('body')[0]; 

var test = new Element('div', {'style':'visibility:hidden; width: 100px; height: 100px; overflow: scroll;'}); 

test.inject(body); 

var scrollbar = { 
    width: test.offsetWidth - test.scrollWidth 
    , height: test.offsetHeight - test.scrollHeight 
} 

test.dispose(); 
Questions connexes