mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-21 21:40:48 +00:00
Scrollbar - remove margin/padding properties properly (#35388)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
parent
c376cb0763
commit
28a5a72ed5
@ -15,8 +15,8 @@ import { isElement } from './index'
|
|||||||
|
|
||||||
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
|
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
|
||||||
const SELECTOR_STICKY_CONTENT = '.sticky-top'
|
const SELECTOR_STICKY_CONTENT = '.sticky-top'
|
||||||
const PROPERTY_PADDING = 'paddingRight'
|
const PROPERTY_PADDING = 'padding-right'
|
||||||
const PROPERTY_MARGIN = 'marginRight'
|
const PROPERTY_MARGIN = 'margin-right'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class definition
|
* Class definition
|
||||||
@ -69,15 +69,15 @@ class ScrollBarHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._saveInitialAttribute(element, styleProp)
|
this._saveInitialAttribute(element, styleProp)
|
||||||
const calculatedValue = window.getComputedStyle(element)[styleProp]
|
const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProp)
|
||||||
element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px`
|
element.style.setProperty(styleProp, `${callback(Number.parseFloat(calculatedValue))}px`)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._applyManipulationCallback(selector, manipulationCallBack)
|
this._applyManipulationCallback(selector, manipulationCallBack)
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveInitialAttribute(element, styleProp) {
|
_saveInitialAttribute(element, styleProp) {
|
||||||
const actualValue = element.style[styleProp]
|
const actualValue = element.style.getPropertyValue(styleProp)
|
||||||
if (actualValue) {
|
if (actualValue) {
|
||||||
Manipulator.setDataAttribute(element, styleProp, actualValue)
|
Manipulator.setDataAttribute(element, styleProp, actualValue)
|
||||||
}
|
}
|
||||||
@ -86,13 +86,14 @@ class ScrollBarHelper {
|
|||||||
_resetElementAttributes(selector, styleProp) {
|
_resetElementAttributes(selector, styleProp) {
|
||||||
const manipulationCallBack = element => {
|
const manipulationCallBack = element => {
|
||||||
const value = Manipulator.getDataAttribute(element, styleProp)
|
const value = Manipulator.getDataAttribute(element, styleProp)
|
||||||
if (typeof value === 'undefined') {
|
// We only want to remove the property if the value is `null`; the value can also be zero
|
||||||
|
if (value === null) {
|
||||||
element.style.removeProperty(styleProp)
|
element.style.removeProperty(styleProp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Manipulator.removeDataAttribute(element, styleProp)
|
Manipulator.removeDataAttribute(element, styleProp)
|
||||||
element.style[styleProp] = value
|
element.style.setProperty(styleProp, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._applyManipulationCallback(selector, manipulationCallBack)
|
this._applyManipulationCallback(selector, manipulationCallBack)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user