-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix scroll problem when scrollbar on html element #1751
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="../../../demo/demo.css"/> | ||
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gridstack-h5.js"></script> --> | ||
<script src="../../../dist/gridstack-h5.js"></script> | ||
<style> | ||
.topHeader { | ||
|
@@ -30,16 +29,37 @@ | |
width: 50px; | ||
box-sizing: border-box; | ||
} | ||
.outer { | ||
display: flex; | ||
} | ||
.main { | ||
flex-grow: 1; | ||
} | ||
.bodyScroll { | ||
height: 2000px; | ||
width: 100px; | ||
flex: 0 0 auto; | ||
border: 3px solid blue; | ||
} | ||
</style> | ||
|
||
</head> | ||
<body> | ||
<div class="topHeader">This is the header which brings an offset of 200 px</div> | ||
<div class="row"> | ||
<div class="showDistance"></div> | ||
<div class="willScroll"> | ||
<div class="grid-stack"></div> | ||
</div> | ||
<div class="outer"> | ||
<div class="main"> | ||
<div class="topHeader"> | ||
This page allows to test scrolling behavior when scroll element is not whole page (html element), | ||
and when the scrolling element is not at the top of the page. Also effects of multiple | ||
scrollbars can be tested, as the html element also can be scrolled.<br> | ||
This is the header which brings an offset of 200 px</div> | ||
<div class="row"> | ||
<div class="showDistance"></div> | ||
<div class="willScroll"> | ||
<div class="grid-stack"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="bodyScroll">This causes the scrollbar on html element</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
|
@@ -48,7 +68,7 @@ | |
{x: 0, y: 0, w: 2, h: 2, content: "resize-me - check scrolling starts only when in height of gray area, and you can scroll back up as well."}, | ||
{x: 3, y: 0, w: 2, h: 2, content: "this is here to have next item positioned way down"}, | ||
{x: 3, y: 2, w: 3, h: 2, content: "resize me - scroll will start immediately, but should not be extremely fast"}, | ||
{x: 6, y: 0, w: 2, h: 8, content: "this is here to have a scroll bar from the beginning"}, | ||
{x: 6, y: 0, w: 2, h: 8, content: "this is here to have a scroll bar on .main div from the beginning"}, | ||
]; | ||
grid.load(items); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,7 +351,18 @@ export class Utils { | |
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void { | ||
const scrollEl = this.getScrollParent(el); | ||
const height = scrollEl.clientHeight; | ||
const offsetTop = scrollEl.getBoundingClientRect().top; | ||
//when does pointer move out of visible area, which is then fixed by scrolling that element? | ||
//property clientHeight returns height of element, but for 'html', it returns | ||
//height of viewport. getBoundingClientRect() returns rect of element in client | ||
//coordinates, for normal elements its height equals clientHeight, but for 'html' | ||
//getBoundingClientRect() returns the location of the total page, height can be much larger | ||
//than viewport height, and when scrolled, top is negative. | ||
//So for 'html', we compare pointer position/height against viewport, for which top is 0, | ||
//if some inner element is our scrollElement, we must compare it to the client position of that element. | ||
let offsetTop = 0; | ||
if (scrollEl != document.scrollingElement) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. !== please also maybe use this.getScrollElement() (which I JUST RENAMED but changed to use document.scrollingElement 2 weeks ago from document.documentElement for Safari and being correct). This way there is only 1 place to change (if ever) |
||
offsetTop = scrollEl.getBoundingClientRect().top; | ||
} | ||
const pointerPosY = event.clientY - offsetTop; | ||
const top = pointerPosY < distance; | ||
const bottom = pointerPosY > height - distance; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure that first line help - also wrong syntax.
Also please change comments to '// ' (add space)
can we maybe rephrase this comment ? It's not helping me. I would document why we need offsetTop at all, THEN explain that document HTML is different due to returning viewport and not actual needed height. or something like that...
I have not looked into this so taking you word for it. Also add #1745 #1727 to your comment.