Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

detect-scrollbar-width problems #43

@somazx

Description

@somazx

I'm attempting to use this component but I'm getting the following error once I add import the module.

Cannot read property 'appendChild' of null

// Refers to https://davidwalsh.name/detect-scrollbar-width
const div = document.createElement('div')

div.style.width = '100px'
div.style.height = '100px'
div.style.overflow = 'scroll'
div.style.position = 'absolute'
div.style.top = '-9999px'

document.body.appendChild(div) /* <---- ERROR IS THIS LINE */

const SCROLLBAR_WIDTH = div.offsetWidth - div.clientWidth

My guess is that this is running before document has loaded or body doesn't exist at this stage? But why should it exist at the point of import?

I'm using this with default Rails 5.1 + Vue/webpacker setup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions