Detectar el ancho de la barra de scroll del navegador con JavaScript

Para detectar el ancho de la barra de scroll del navegador podemos usar este pequeño código:

function anchoBarraNavegador()
{
    var scrollDiv = document.createElement("div");
    scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; \
    			       position: absolute; top: -9999px;';
    document.body.appendChild(scrollDiv);

    var scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth;
	
    document.body.removeChild(scrollDiv);

    return scrollbarSize;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.