Reduce cls by toggling padding value on body element

This commit is contained in:
Björn Fromme
2022-03-14 13:45:52 +01:00
parent 721a1be51d
commit cd895c060d
2 changed files with 10 additions and 1 deletions
@@ -9,6 +9,7 @@ export default class extends Controller {
sticky: Boolean, sticky: Boolean,
classes: String, classes: String,
offset: Number, offset: Number,
padding: String,
disabled: Boolean, disabled: Boolean,
} }
@@ -35,7 +36,14 @@ export default class extends Controller {
this.stickyValue = window.scrollY > this.offsetValue this.stickyValue = window.scrollY > this.offsetValue
} }
stickyValueChanged() { stickyValueChanged(value) {
if (this.hasPaddingValue) {
if (true === value) {
document.body.style.paddingTop = this.paddingValue
} else {
document.body.removeAttribute('style')
}
}
if (!this.hasClassesValue) { if (!this.hasClassesValue) {
return return
} }
@@ -23,6 +23,7 @@
<f:else> <f:else>
data-controller="sticky" data-controller="sticky"
data-sticky-offset-value="650" data-sticky-offset-value="650"
data-sticky-padding-value="7.5rem"
data-sticky-disabled-value="false" data-sticky-disabled-value="false"
data-sticky-classes-value="sticky reduced" data-sticky-classes-value="sticky reduced"
</f:else> </f:else>