Skip to content

timhjellum/get-window-client-dimentions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Get Window Client Dimentions

Paste the below JavaScript:

const isSupported = () => typeof window !== 'undefined'
const getWindowWidth = () => {
  if (!isSupported()) {
    return 0
  }
  return (
    document.getElementsByTagName('body')[0].clientWidth
  )
}

const isSupported = () => typeof window !== 'undefined'
const getActualWidth = () => {
  if (!isSupported()) {
    return 0
  }
  return (
    window.innerWidth
  )
}

in your .JS file

window.addEventListener('scroll', runScript)
window.addEventListener('resize', runScript)
window.addEventListener('load', runScript)

function runScript() {
  console.log((getWindowWidth() + 'px')
  console.log((getActualWidth() + 'px')
}

See it in action: https://jsfiddle.net/timhjellum/ze2wvax8/.

About

Get Window Width

https://jsfiddle.net/timhjellum/ze2wvax8/

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published