Skip to content

Commit

Permalink
Scroll to top on iOS (#1777)
Browse files Browse the repository at this point in the history
Closes #1734.
  • Loading branch information
paulo-valim authored Sep 18, 2023
1 parent 415762c commit 21254a5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
19 changes: 7 additions & 12 deletions assets/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body {

body {
--sidebarWidth: 300px;
--sidebarTransitionDuration: .3s;
--sidebarTransitionDuration: 0.3s;
background-color: var(--background);
color: var(--textBody);
font-size: 16px;
Expand Down Expand Up @@ -57,15 +57,10 @@ body {
z-index: 3;
}

@media screen and (max-width: 768px) {
.content {
overflow: auto;
scroll-padding-top: 45px;
}
}

body:is(.sidebar-opening, .sidebar-opened) .sidebar-button {
transform: translateX(calc(var(--sidebarWidth) - 100% - var(--sidebarButtonRightOpen)));
transform: translateX(
calc(var(--sidebarWidth) - 100% - var(--sidebarButtonRightOpen))
);
top: var(--sidebarButtonTopOpen);
}

Expand Down Expand Up @@ -117,7 +112,7 @@ body.sidebar-closed .content {
@media screen and (max-width: 768px) {
.sidebar-button:before {
--sidebarButtonHeight: 60px;
content: '';
content: "";
display: block;
z-index: -1;
pointer-events: none;
Expand Down Expand Up @@ -145,13 +140,13 @@ body.sidebar-closed .content {

body.search-focused .sidebar-button {
transform: translateX(250px) scaleY(0);
transition: all .15s ease-out;
transition: all 0.15s ease-out;
opacity: 0;
}

body.search-focused .sidebar-search .search-close-button {
transform: scaleY(1);
transition: transform .15s ease-out .15s;
transition: transform 0.15s ease-out 0.15s;
}

.content-inner {
Expand Down
20 changes: 20 additions & 0 deletions assets/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,23 @@ function getLivebookDevRunUrl (notebookUrl) {
function getLivebookImportUrl (livebookUrl, notebookUrl) {
return `${livebookUrl}/import?url=${encodeURIComponent(notebookUrl)}`
}

// Check if the device width is below a certain threshold (e.g., 768px for mobile)
document.addEventListener('click', function (e) {
if (window.innerWidth <= 768) {
const target = e.target.closest('a[href^="#"]')
if (target) {
e.preventDefault()
const targetId = target.getAttribute('href').substring(1)
const targetElement = document.getElementById(targetId)
if (targetElement) {
const offset = 45 // Adjust this offset as needed
const targetPosition = targetElement.getBoundingClientRect().top + window.scrollY - offset
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
})
}
}
}
})
56 changes: 56 additions & 0 deletions formatters/html/dist/html-GGSI4AXI.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions formatters/html/dist/html-elixir-BVKXBYYG.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions formatters/html/dist/html-erlang-LLGHZUND.css

Large diffs are not rendered by default.

0 comments on commit 21254a5

Please sign in to comment.