This repository was archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Fix/issue 31 fullpage scroll #32
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| /** | ||
| * Hide the scrollbars | ||
| * | ||
| * There is a `try/catch` for this issue | ||
| * https://github.com/wswebcreation/webdriver-image-comparison/issues/30 | ||
| * Some browsers don't wrap XML into a body element, so this will fail | ||
| */ | ||
| export default function hideScrollBars(hide: boolean): void { | ||
| if (hide) { | ||
| document.body.style.overflow = 'hidden'; | ||
| } else { | ||
| document.body.style.overflow = ''; | ||
| try { | ||
| if (hide) { | ||
| document.body.style.overflow = 'hidden'; | ||
| } else { | ||
| document.body.style.overflow = ''; | ||
| } | ||
| } catch (e) { | ||
| // Do nothing | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,57 +1,8 @@ | ||
| /** | ||
| * Scroll to a x = 0 and y = variable position in the screen | ||
| * Sometimes a scroll can't be done on the window, so the scroll needs to be done on the largest | ||
| * element on the screen | ||
| * Scroll to y = variable position in the screen | ||
| */ | ||
| /* istanbul ignore next */ | ||
| export default function scrollToPosition(yPosition: number): void { | ||
| const initialScroll = document.documentElement.scrollTop; | ||
|
|
||
| // If for some reason the scroll didn't work, find the first largest element and use that to scroll on | ||
| let largestNode: HTMLElement; | ||
|
|
||
| // Scroll with the default way of scrolling | ||
| window.scrollTo(0, yPosition); | ||
|
|
||
| /* istanbul ignore else */ | ||
| if (initialScroll === document.documentElement.scrollTop && yPosition > 0) { | ||
| largestFirstNode(document.documentElement.childNodes).scrollTo(0, yPosition); | ||
| } | ||
|
|
||
| /** | ||
| * Find the first largest node in the page so it can be used for scrolling | ||
| */ | ||
| function largestFirstNode(nodesList: any) { | ||
| let node: HTMLElement; | ||
|
|
||
| // Loop over the nodes | ||
| for (let i = nodesList.length - 1; i >= 0; i--) { | ||
| node = nodesList[i]; | ||
|
|
||
| // Stop if the largest node has been found | ||
| /* istanbul ignore next */ | ||
| if (largestNode) { | ||
| break; | ||
| } | ||
|
|
||
| // Check if the element has a scroll / client height | ||
| /* istanbul ignore next */ | ||
| if (node.scrollHeight && node.clientHeight) { | ||
| const viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); | ||
| const elHeight = Math.max(node.scrollHeight, node.clientHeight); | ||
|
|
||
| // If the element is bigger than the viewport, then we got our scroll container | ||
| if (elHeight > viewPortHeight) { | ||
| largestNode = node; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (node.childNodes.length) { | ||
| largestFirstNode(node.childNodes); | ||
| } | ||
| } | ||
|
|
||
| // If the largestNode is the body then return the window | ||
| return (document.body === largestNode || !largestNode) ? window : largestNode; | ||
| } | ||
| (document.scrollingElement || document.documentElement).scrollTop = yPosition; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.