Skip to content

Instantly share code, notes, and snippets.

@daltonmenezes
Created March 16, 2020 03:44
Show Gist options
  • Save daltonmenezes/02029830cc986543781c570f14efba99 to your computer and use it in GitHub Desktop.
Save daltonmenezes/02029830cc986543781c570f14efba99 to your computer and use it in GitHub Desktop.
Get pixel value by increment in javascript to handle element sizes
const pixel = ((init = 0) => {
let pixelValue = init
function increment(value) {
pixelValue += value
}
return {
getByIncrement: value => {
increment(value)
return pixelValue + 'px'
}
}
})()
console.log(
pixel.getByIncrement(100), // 100px
pixel.getByIncrement(100) // 200px
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment