Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get browser width another solution #2708

Open
newbie78 opened this issue Apr 5, 2015 · 2 comments
Open

get browser width another solution #2708

newbie78 opened this issue Apr 5, 2015 · 2 comments

Comments

@newbie78
Copy link

newbie78 commented Apr 5, 2015

it would seem to me to add to the core or more not badly

Document.implement({
    getScrollWidth: function(){
        var scrollDiv=new Element('div',{
            styles:{
                width: '100px',
                height: '100px',
                overflow: 'scroll',
                position: 'absolute',
                top: '-9999px'
            }
        }).inject($(document.body));
        var scrollbarWidth=scrollDiv.offsetWidth-scrollDiv.clientWidth;
        scrollDiv.destroy();
        return scrollbarWidth;
    },
});

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/10515827-get-browser-width-another-solution?utm_campaign=plugin&utm_content=tracker%2F22067&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F22067&utm_medium=issues&utm_source=github).
@SergioCrisostomo
Copy link
Member

@newbie78 thank you for the suggestion!

Personally I don't think this should be part of Core. Adding a div to the DOM should be avoided, even if its a valid way to retrieve the scroll-bar width. Reminds me of this other way in Stackoverfow.
Maybe this would fit More, or a separate plugin better than Core.

I will close this soon if no one has a different opinion.

@DimitarChristoff
Copy link
Member

this won't scale as you can override scrollbar widths on a per-element basis based upon cascading styles.

eg.

::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

.dark ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

... which means you can only truly measure scrollbar width on an element by injecting exactly where the element is (hopefully not in conflict with n-th child selectors)... I'd write this as a plugin or possibly mootools-more - extending http://mootools.net/more/docs/1.5.1/Element/Element.Measure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants