mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-22 09:00:38 +03:00
padding absolute test
This commit is contained in:
+10
-1
@@ -5,7 +5,16 @@ import { addClass } from 'support';
|
|||||||
const url = new URL(window.location.toString());
|
const url = new URL(window.location.toString());
|
||||||
const params = url.searchParams;
|
const params = url.searchParams;
|
||||||
|
|
||||||
['nss', 'fbg', 'ccp', 'po', 'fo', 'tvp'].forEach((param) => {
|
/**
|
||||||
|
* nsh: native scrollbar hiding
|
||||||
|
* fbg: flexbox glue
|
||||||
|
* ccp: css custom props
|
||||||
|
* po: partially overlaid
|
||||||
|
* fo: fully overlaid
|
||||||
|
* vpt: viewport is target
|
||||||
|
* pa: padding absolute
|
||||||
|
*/
|
||||||
|
['nsh', 'fbg', 'ccp', 'po', 'fo', 'vpt', 'pa'].forEach((param) => {
|
||||||
const paramValue = Boolean(params.get(param));
|
const paramValue = Boolean(params.get(param));
|
||||||
|
|
||||||
if (paramValue) {
|
if (paramValue) {
|
||||||
|
|||||||
+56
-32
@@ -2,6 +2,7 @@ import 'index.scss';
|
|||||||
import './index.scss';
|
import './index.scss';
|
||||||
import './handleEnvironment';
|
import './handleEnvironment';
|
||||||
import { OverlayScrollbars } from 'overlayscrollbars';
|
import { OverlayScrollbars } from 'overlayscrollbars';
|
||||||
|
import { classNameViewport } from 'classnames';
|
||||||
import should from 'should';
|
import should from 'should';
|
||||||
import {
|
import {
|
||||||
generateClassChangeSelectCallback,
|
generateClassChangeSelectCallback,
|
||||||
@@ -25,6 +26,7 @@ import {
|
|||||||
appendChildren,
|
appendChildren,
|
||||||
createDOM,
|
createDOM,
|
||||||
hasClass,
|
hasClass,
|
||||||
|
createDiv,
|
||||||
} from 'support';
|
} from 'support';
|
||||||
import { Options } from 'options';
|
import { Options } from 'options';
|
||||||
import { DeepPartial } from 'typings';
|
import { DeepPartial } from 'typings';
|
||||||
@@ -100,6 +102,7 @@ const msedge = window.navigator.userAgent.toLowerCase().indexOf('edge') > -1;
|
|||||||
|
|
||||||
msie11 && addClass(document.body, 'msie11');
|
msie11 && addClass(document.body, 'msie11');
|
||||||
|
|
||||||
|
const paddingAbsolute = hasClass(document.body, 'pa');
|
||||||
const useContentElement = false;
|
const useContentElement = false;
|
||||||
const fixedDigits = msie11 ? 1 : 3;
|
const fixedDigits = msie11 ? 1 : 3;
|
||||||
const fixedDigitsOffset = 3;
|
const fixedDigitsOffset = 3;
|
||||||
@@ -118,21 +121,9 @@ const comparisonEnd: HTMLElement | null = document.querySelector('#comparison .e
|
|||||||
const targetOptionsSlot: HTMLElement | null = document.querySelector('#options');
|
const targetOptionsSlot: HTMLElement | null = document.querySelector('#options');
|
||||||
const targetUpdatesSlot: HTMLElement | null = document.querySelector('#updates');
|
const targetUpdatesSlot: HTMLElement | null = document.querySelector('#updates');
|
||||||
const comparisonContentElm: HTMLElement = document.createElement('div');
|
const comparisonContentElm: HTMLElement = document.createElement('div');
|
||||||
|
|
||||||
const envElms = document.querySelectorAll<HTMLElement>('.env');
|
const envElms = document.querySelectorAll<HTMLElement>('.env');
|
||||||
|
|
||||||
if (!useContentElement) {
|
const initObj = hasClass(document.body, 'vpt')
|
||||||
envElms.forEach((elm) => {
|
|
||||||
addClass(elm, 'intrinsicHack');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const elms = contents(comparison);
|
|
||||||
addClass(comparisonContentElm, 'comparisonContent');
|
|
||||||
appendChildren(comparison, comparisonContentElm);
|
|
||||||
appendChildren(comparisonContentElm, elms);
|
|
||||||
}
|
|
||||||
|
|
||||||
const initObj = hasClass(document.body, 'tvp')
|
|
||||||
? {
|
? {
|
||||||
target: target!,
|
target: target!,
|
||||||
elements: {
|
elements: {
|
||||||
@@ -148,12 +139,15 @@ const initObj = hasClass(document.body, 'tvp')
|
|||||||
};
|
};
|
||||||
|
|
||||||
let updateCount = 0;
|
let updateCount = 0;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const osInstance =
|
const osInstance =
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
(window.os = OverlayScrollbars(
|
(window.os = OverlayScrollbars(
|
||||||
initObj,
|
initObj,
|
||||||
{},
|
{
|
||||||
|
paddingAbsolute,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
updated() {
|
updated() {
|
||||||
updateCount++;
|
updateCount++;
|
||||||
@@ -162,16 +156,25 @@ const osInstance =
|
|||||||
targetUpdatesSlot.textContent = `${updateCount}`;
|
targetUpdatesSlot.textContent = `${updateCount}`;
|
||||||
}
|
}
|
||||||
if (targetOptionsSlot) {
|
if (targetOptionsSlot) {
|
||||||
targetOptionsSlot.textContent = JSON.stringify(osInstance.options().overflow, null, 2);
|
targetOptionsSlot.textContent = JSON.stringify(
|
||||||
|
assignDeep({}, osInstance.options().overflow, {
|
||||||
|
paddingAbsolute: osInstance.options().paddingAbsolute,
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const getComparisonViewport = () =>
|
||||||
|
paddingAbsolute ? (comparison!.firstElementChild as HTMLElement) : comparison;
|
||||||
const getMetrics = (elm: HTMLElement): Metrics => {
|
const getMetrics = (elm: HTMLElement): Metrics => {
|
||||||
// const rounding = isFractionalPixelRatio() ? Math.round : (num: number) => num;
|
// const rounding = isFractionalPixelRatio() ? Math.round : (num: number) => num;
|
||||||
const elmIsTarget = elm === target;
|
const elmIsTarget = elm === target;
|
||||||
|
const comparisonViewport = getComparisonViewport();
|
||||||
const comparisonEnvBCR = getBoundingClientRect(parent(elm!) as HTMLElement);
|
const comparisonEnvBCR = getBoundingClientRect(parent(elm!) as HTMLElement);
|
||||||
const comparisonBCR = getBoundingClientRect(elm!);
|
const comparisonBCR = getBoundingClientRect(elm!);
|
||||||
const comparisonPercentBCR = getBoundingClientRect(elm!.querySelector('.percent')!);
|
const comparisonPercentBCR = getBoundingClientRect(elm!.querySelector('.percent')!);
|
||||||
@@ -179,9 +182,10 @@ const getMetrics = (elm: HTMLElement): Metrics => {
|
|||||||
const scrollMeasure = () => {
|
const scrollMeasure = () => {
|
||||||
const condition = (raw: number) => (window.devicePixelRatio % 1 !== 0 ? raw > 1 : raw > 0);
|
const condition = (raw: number) => (window.devicePixelRatio % 1 !== 0 ? raw > 1 : raw > 0);
|
||||||
const amount = {
|
const amount = {
|
||||||
width: Math.max(0, comparison!.scrollWidth - comparison!.clientWidth),
|
width: Math.max(0, comparisonViewport!.scrollWidth - comparisonViewport!.clientWidth),
|
||||||
height: Math.max(0, comparison!.scrollHeight - comparison!.clientHeight),
|
height: Math.max(0, comparisonViewport!.scrollHeight - comparisonViewport!.clientHeight),
|
||||||
};
|
};
|
||||||
|
console.log(elm, amount, comparisonViewport);
|
||||||
return {
|
return {
|
||||||
width: condition(amount.width) ? amount.width : 0,
|
width: condition(amount.width) ? amount.width : 0,
|
||||||
height: condition(amount.height) ? amount.height : 0,
|
height: condition(amount.height) ? amount.height : 0,
|
||||||
@@ -604,12 +608,6 @@ const iterateMinMax = async (afterEach?: () => any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
||||||
const additiveOverflow = () => {
|
|
||||||
if (isFractionalPixelRatio()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
const contentBox = (elm: HTMLElement | null): WH<number> => {
|
const contentBox = (elm: HTMLElement | null): WH<number> => {
|
||||||
if (elm) {
|
if (elm) {
|
||||||
const computedStyle = window.getComputedStyle(elm);
|
const computedStyle = window.getComputedStyle(elm);
|
||||||
@@ -640,13 +638,14 @@ const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
|||||||
const { maxWidth, maxHeight } = style(comparison, ['maxWidth', 'maxHeight']);
|
const { maxWidth, maxHeight } = style(comparison, ['maxWidth', 'maxHeight']);
|
||||||
|
|
||||||
if (maxWidth !== 'none' && maxHeight !== 'none') {
|
if (maxWidth !== 'none' && maxHeight !== 'none') {
|
||||||
const addOverflow = additiveOverflow();
|
const addOverflow = 1;
|
||||||
const before: CheckComparisonObj = {
|
const before: CheckComparisonObj = {
|
||||||
updCount: updateCount,
|
updCount: updateCount,
|
||||||
metrics: getMetrics(comparison!),
|
metrics: getMetrics(comparison!),
|
||||||
};
|
};
|
||||||
const { paddingRight, paddingBottom } = style(comparison, ['paddingRight', 'paddingBottom']);
|
const { paddingRight, paddingBottom } = style(comparison, ['paddingRight', 'paddingBottom']);
|
||||||
const comparisonContentBox = contentBox(comparison);
|
const comparisonViewport = getComparisonViewport();
|
||||||
|
const comparisonContentBox = contentBox(comparisonViewport);
|
||||||
const widthOverflow = width ? comparisonContentBox.w + addOverflow : 0;
|
const widthOverflow = width ? comparisonContentBox.w + addOverflow : 0;
|
||||||
const heightOverflow = height ? comparisonContentBox.h + addOverflow : 0;
|
const heightOverflow = height ? comparisonContentBox.h + addOverflow : 0;
|
||||||
const styleObj = { width: widthOverflow, height: heightOverflow };
|
const styleObj = { width: widthOverflow, height: heightOverflow };
|
||||||
@@ -654,8 +653,8 @@ const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
|||||||
style(comparisonResize, styleObj);
|
style(comparisonResize, styleObj);
|
||||||
|
|
||||||
const overflowAmount = {
|
const overflowAmount = {
|
||||||
width: comparison!.scrollWidth - comparison!.clientWidth,
|
width: comparisonViewport!.scrollWidth - comparisonViewport!.clientWidth,
|
||||||
height: comparison!.scrollHeight - comparison!.clientHeight,
|
height: comparisonViewport!.scrollHeight - comparisonViewport!.clientHeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (width && overflowAmount.width <= 0) {
|
if (width && overflowAmount.width <= 0) {
|
||||||
@@ -668,22 +667,28 @@ const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
|||||||
style(comparisonResize, styleObj);
|
style(comparisonResize, styleObj);
|
||||||
|
|
||||||
if (width) {
|
if (width) {
|
||||||
while (comparison!.scrollWidth - comparison!.clientWidth <= addOverflow - 1) {
|
while (
|
||||||
|
comparisonViewport!.scrollWidth - comparisonViewport!.clientWidth <=
|
||||||
|
addOverflow - 1
|
||||||
|
) {
|
||||||
styleObj.width += addOverflow;
|
styleObj.width += addOverflow;
|
||||||
style(comparisonResize, styleObj);
|
style(comparisonResize, styleObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (height) {
|
if (height) {
|
||||||
while (comparison!.scrollHeight - comparison!.clientHeight <= addOverflow - 1) {
|
while (
|
||||||
|
comparisonViewport!.scrollHeight - comparisonViewport!.clientHeight <=
|
||||||
|
addOverflow - 1
|
||||||
|
) {
|
||||||
styleObj.height += addOverflow;
|
styleObj.height += addOverflow;
|
||||||
style(comparisonResize, styleObj);
|
style(comparisonResize, styleObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const overflowAmountCheck = {
|
const overflowAmountCheck = {
|
||||||
width: comparison!.scrollWidth - comparison!.clientWidth,
|
width: comparisonViewport!.scrollWidth - comparisonViewport!.clientWidth,
|
||||||
height: comparison!.scrollHeight - comparison!.clientHeight,
|
height: comparisonViewport!.scrollHeight - comparisonViewport!.clientHeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
await waitForOrFailTest(() => {
|
await waitForOrFailTest(() => {
|
||||||
@@ -724,7 +729,8 @@ const overflowTest = async (osOptions?: DeepPartial<Options>) => {
|
|||||||
updCount: updateCount,
|
updCount: updateCount,
|
||||||
metrics: getMetrics(comparison!),
|
metrics: getMetrics(comparison!),
|
||||||
};
|
};
|
||||||
const comparisonContentBox = contentBox(comparison);
|
const comparisonViewport = getComparisonViewport();
|
||||||
|
const comparisonContentBox = contentBox(comparisonViewport);
|
||||||
const widthOverflow = width ? comparisonContentBox.w + 1000 : 0;
|
const widthOverflow = width ? comparisonContentBox.w + 1000 : 0;
|
||||||
const heightOverflow = height ? comparisonContentBox.h + 1000 : 0;
|
const heightOverflow = height ? comparisonContentBox.h + 1000 : 0;
|
||||||
const styleObj = { width: widthOverflow, height: heightOverflow };
|
const styleObj = { width: widthOverflow, height: heightOverflow };
|
||||||
@@ -825,3 +831,21 @@ const start = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
startBtn?.addEventListener('click', start);
|
startBtn?.addEventListener('click', start);
|
||||||
|
|
||||||
|
if (!useContentElement) {
|
||||||
|
envElms.forEach((elm) => {
|
||||||
|
addClass(elm, 'intrinsicHack');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const elms = contents(comparison);
|
||||||
|
addClass(comparisonContentElm, 'comparisonContent');
|
||||||
|
appendChildren(comparison, comparisonContentElm);
|
||||||
|
appendChildren(comparisonContentElm, elms);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paddingAbsolute) {
|
||||||
|
const absoluteWrapper = createDiv(classNameViewport);
|
||||||
|
appendChildren(absoluteWrapper, contents(comparison));
|
||||||
|
|
||||||
|
appendChildren(comparison, absoluteWrapper);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<div id="controls">
|
<div id="controls">
|
||||||
<button id="nss">Without Native Scrollbar Styling</button>
|
<button id="nsh">Without Native Scrollbar Hiding</button>
|
||||||
<button id="fbg">Without Flexbox Glue</button>
|
<button id="fbg">Without Flexbox Glue</button>
|
||||||
<button id="ccp">Without CSS Custom Props</button>
|
<button id="ccp">Without CSS Custom Props</button>
|
||||||
<button id="po">Partially Overlaid</button>
|
<button id="po">Partially Overlaid</button>
|
||||||
<button id="fo">Fully Overlaid</button>
|
<button id="fo">Fully Overlaid</button>
|
||||||
<button id="tvp">Target Is Viewport</button>
|
<button id="vpt">Target Is Viewport</button>
|
||||||
|
<button id="pa">Padding Absolute</button>
|
||||||
<br />
|
<br />
|
||||||
<label for="envHeight">envHeight</label>
|
<label for="envHeight">envHeight</label>
|
||||||
<select name="envHeight" id="envHeight">
|
<select name="envHeight" id="envHeight">
|
||||||
|
|||||||
+25
-17
@@ -189,18 +189,6 @@ body {
|
|||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.paddingNone > .container {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paddingSmall > .container {
|
|
||||||
padding: 5px 50px 15px 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paddingLarge > .container {
|
|
||||||
padding: 12px 22px 53px 33px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.borderNone > .container {
|
.borderNone > .container {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
@@ -229,6 +217,18 @@ body {
|
|||||||
margin: 33px 46px 69px 23px;
|
margin: 33px 46px 69px 23px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.paddingNone > .container {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paddingSmall > .container {
|
||||||
|
padding: 5px 50px 15px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paddingLarge > .container {
|
||||||
|
padding: 12px 22px 53px 33px;
|
||||||
|
}
|
||||||
|
|
||||||
.boxSizingBorderBox > .container {
|
.boxSizingBorderBox > .container {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disable native scrollbar styling detection
|
// disable native scrollbar styling detection
|
||||||
.nss {
|
body.nsh {
|
||||||
.os-viewport-scrollbar-hidden.os-environment {
|
.os-viewport-scrollbar-hidden.os-environment {
|
||||||
scrollbar-width: auto !important;
|
scrollbar-width: auto !important;
|
||||||
}
|
}
|
||||||
@@ -308,21 +308,21 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disable flexboxglue detection
|
// disable flexboxglue detection
|
||||||
.fbg {
|
body.fbg {
|
||||||
.os-environment-flexbox-glue.os-environment {
|
.os-environment-flexbox-glue.os-environment {
|
||||||
display: block !important;
|
display: block !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable css custom props detection
|
// disable css custom props detection
|
||||||
.ccp {
|
body.ccp {
|
||||||
.os-environment {
|
.os-environment {
|
||||||
z-index: 0 !important;
|
z-index: 0 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fully overlaid
|
// fully overlaid
|
||||||
.fo {
|
body.fo {
|
||||||
.os-environment::-webkit-scrollbar,
|
.os-environment::-webkit-scrollbar,
|
||||||
.os-viewport::-webkit-scrollbar,
|
.os-viewport::-webkit-scrollbar,
|
||||||
.os-environment::-webkit-scrollbar-corner,
|
.os-environment::-webkit-scrollbar-corner,
|
||||||
@@ -342,7 +342,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// partially overlaid (chrome only)
|
// partially overlaid (chrome only)
|
||||||
.po {
|
body.po {
|
||||||
.os-environment::-webkit-scrollbar,
|
.os-environment::-webkit-scrollbar,
|
||||||
.os-viewport::-webkit-scrollbar,
|
.os-viewport::-webkit-scrollbar,
|
||||||
.os-environment::-webkit-scrollbar-corner,
|
.os-environment::-webkit-scrollbar-corner,
|
||||||
@@ -353,3 +353,11 @@ body {
|
|||||||
background: red !important;
|
background: red !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// padding absolute
|
||||||
|
body.pa #comparison {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
body.pa .widthAuto > #comparison {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user