Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Fix for OSX auto hiding scrollbars (#103)
Browse files Browse the repository at this point in the history
* Fix for OSX auto hiding scrollbars
* Move fallback scrollbar size to const
  • Loading branch information
eirikbacker authored Aug 10, 2018
1 parent 2adb5e2 commit d4bb6e8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core-scroll/core-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ATTR = 'data-core-scroll'
const UUID = `data-${name}-${version}`.replace(/\W+/g, '-') // Strip invalid attribute characters
const MOVE = {up: {y: -1, prop: 'top'}, down: {y: 1, prop: 'bottom'}, left: {x: -1}, right: {x: 1}}
const SIGNIFICANT_DRAG_THRESHOLD = 10
const FALLBACK_SCROLLBAR_SIZE = 18
const FRICTION = 0.8
const VELOCITY = 20

Expand All @@ -23,9 +24,12 @@ export default function scroll (elements, move = '') {
target.style.willChange = 'scroll-position' // Enhance performace
target.style.webkitOverflowScrolling = 'touch' // Momentum scoll on iOS

// Must be after setting overflow scroll
const scrollbarWidth = target.offsetWidth - target.clientWidth + 1 // Plus one fixes safari pixelbug
const scrollbarHeight = target.offsetHeight - target.clientHeight + 1 // Plus one fixes safari pixelbug
// Calculate scrollBareSizes for hiding
// Must be after setting overflow:scroll
// Default to 18px (max reports scrollbar size 0 when "auto hiding")
// Plus one fixes safari pixelbug
const scrollbarWidth = (target.offsetWidth - target.clientWidth || FALLBACK_SCROLLBAR_SIZE) + 1
const scrollbarHeight = (target.offsetHeight - target.clientHeight || FALLBACK_SCROLLBAR_SIZE) + 1

target.style.maxHeight = `calc(100% + ${scrollbarHeight}px)` // Consistent height
target.style.marginRight = `-${scrollbarWidth}px`
Expand Down

0 comments on commit d4bb6e8

Please sign in to comment.